Skip to content

Instantly share code, notes, and snippets.

@mdarby
Created January 4, 2009 16:04
Show Gist options
  • Save mdarby/43082 to your computer and use it in GitHub Desktop.
Save mdarby/43082 to your computer and use it in GitHub Desktop.
# Usage:
# >> User.random
# => #<User login: ...
class ActiveRecord::Base
def self.random
begin
find(rand(count))
rescue ActiveRecord::RecordNotFound
self.random
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment