Module: ActiveRecord::RandomRecord
- Defined in:
- lib/random_record.rb
Instance Method Summary collapse
Instance Method Details
#random(count = 1) ⇒ Object
7 8 9 10 |
# File 'lib/random_record.rb', line 7 def random(count=1) return (count == 1) ? nil : [] if self.count == 0 count == 1 ? offset(rand(self.count)).first : all.sort_by { rand }.sort_by { rand }.slice(0...count) end |