Skip to content

Instantly share code, notes, and snippets.

@Kameshwaran
Last active August 29, 2015 14:13
Show Gist options
  • Save Kameshwaran/42b7c1604d76b7a12fdd to your computer and use it in GitHub Desktop.
Save Kameshwaran/42b7c1604d76b7a12fdd to your computer and use it in GitHub Desktop.
simple random implementation in ActiveRecord instances
class ActiveRecord::Base
class << self
def random
all.at(rand(count))
end
end
end
# User.random => #<User id: 10, ...>
# User.random => #<User id: 59, ...>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment