Need to get a random record? Fortunately databases have built-in functions for this.


# For PostgreSQL and SQLite
Model.order("RANDOM()").first

# For MySQL
Model.order("RAND()").first


Related External Links: