Last active
November 18, 2015 12:33
-
-
Save tjmw/b7dd38dd30f8e2d791bb to your computer and use it in GitHub Desktop.
Deterministically sort an array based on the date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # requires active_support | |
| list = [:foo, :bar, :baz] | |
| # Today: | |
| seed = Time.find_zone!('America/Los_Angeles').today.at_beginning_of_day.to_i | |
| list.shuffle(random: Random.new(seed)) # => [:bar, :baz, :foo] | |
| list.shuffle(random: Random.new(seed)) # => [:bar, :baz, :foo] | |
| # Tomorrow: | |
| seed = (Time.find_zone!('America/Los_Angeles').today + 1).at_beginning_of_day.to_i | |
| list.shuffle(random: Random.new(seed)) # => [:baz, :foo, :bar] | |
| list.shuffle(random: Random.new(seed)) # => [:baz, :foo, :bar] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment