Skip to content

Instantly share code, notes, and snippets.

@coleww
Created July 18, 2014 14:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coleww/55cea96ff08dd30af611 to your computer and use it in GitHub Desktop.
Save coleww/55cea96ff08dd30af611 to your computer and use it in GitHub Desktop.
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