Created
August 21, 2010 17:11
-
-
Save terrafied/542574 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Randomizer | |
def self.included(base) | |
base.extend ClassMethods | |
end | |
module ClassMethods | |
def some(num = 5) | |
find :all, :order => 'random()', :offset => (count * rand).to_i, :limit => num | |
end | |
def one | |
find(:all, :order => 'random()', :offset => (count * rand).to_i, :limit => 1)[0] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment