Skip to content

Instantly share code, notes, and snippets.

@tyler
Forked from kpumuk/gist:54141
Created January 29, 2009 01:02
Show Gist options
  • Save tyler/54295 to your computer and use it in GitHub Desktop.
Save tyler/54295 to your computer and use it in GitHub Desktop.
# Usage:
# >> User.random
# => #<User login: ...
class ActiveRecord::Base
def self.random
cc = count
begin
find(rand(cc))
rescue ActiveRecord::RecordNotFound
retry
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment