Method: Random::HashExtensions#shuffle
- Defined in:
- lib/standard/facets/random.rb
#shuffle ⇒ Object
Returns a copy of the hash with values arranged in new random order.
h = {:a=>1, :b=>2, :c=>3}
h.shuffle #~> {:b=>2, :c=>1, :a>3}
338 339 340 |
# File 'lib/standard/facets/random.rb', line 338 def shuffle ::Hash.zip( keys.sort_by{Random.number}, values.sort_by{Random.number} ) end |