Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 1e16603c46
Fetching contributors…

Cannot retrieve contributors at this time

23 lines (18 sloc) 0.44 kB
class ActiveRecord::Base
def self.find_one_random
find(:first, :offset => rand(count))
end
def self.find_random how_many
find(find_random_ids(how_many))
end
def self.find_random_ids how_many
all_ids = respond_to?(:find_ids) ?
find_ids :
find(:all, :select => 'id').map { |e| e.id }
ids = []
how_many.times do
ids << all_ids.delete_at(rand(all_ids.size))
end
ids
end
end
Jump to Line
Something went wrong with that request. Please try again.