Skip to content

Commit

Permalink
refactoring + specs
Browse files Browse the repository at this point in the history
  • Loading branch information
grosser committed Dec 28, 2008
1 parent b128864 commit 03aa7a7
Showing 1 changed file with 1 addition and 10 deletions.
11 changes: 1 addition & 10 deletions init.rb 100755 → 100644
@@ -1,10 +1 @@
class ActiveRecord::Base
def self.random(num=1,options={})
return [] if num.zero?
num_records = options.delete(:count) || count
highest_possible_offset = [0,num_records-num].max
offset = [rand(num_records),highest_possible_offset].min
limit = [num,num_records].min
find(:all, {:offset => offset, :limit=>limit}.merge(options))
end
end
require 'random_records'

0 comments on commit 03aa7a7

Please sign in to comment.