I’ve just released random-rails, a new Ruby gem that provides a blazing-fast way to get random records in Rails.
Unlike common approaches that rely on ORDER BY RANDOM() or large offsets, this gem is optimized specifically for PostgreSQL and designed for perfect performance even on large datasets.
It’s simple, lightweight, and works seamlessly with ActiveRecord scopes.
Because if someone is requesting a strategy that’s not actually used (because they’re not using postgres) then something is happening they didn’t expect.
In my projects I tend to be more radical, and raise in such cases. But I never was a custodian of a gem, so I’m hesitant to suggest that.