Skip to content

Instantly share code, notes, and snippets.

@davidakachaos
Created September 13, 2017 13:38
Show Gist options
  • Save davidakachaos/b0129b73e4c26ba19e0c816e1d1435f7 to your computer and use it in GitHub Desktop.
Save davidakachaos/b0129b73e4c26ba19e0c816e1d1435f7 to your computer and use it in GitHub Desktop.
Return a random ActiveRecord object
module ActiveRecord
class Base
def self.random(max_records = 10_000)
find(limit(max_records).pluck(primary_key).sample)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment