Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
weighted shuffle in ruby.
things.sort_by do |thing|
-((thing.created_at.to_f / Time.now.to_f) * rand)
end
@coleww
Copy link
Author

coleww commented Jul 18, 2014

for when the client wants results sorted randomly AND by most recent >_<

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment