Module | Random::HashExtensions
In: | lib/standard/facets/random.rb

### Methods

at_rand at_rand! pick pick_key pick_pair rand_key rand_key! rand_pair rand_pair! rand_value rand_value! shuffle shuffle!

### Public Instance methods

at_rand()

Alias for rand_value

at_rand!()

Alias for rand_value!

pick()

Alias for rand_value!

pick_key()

Alias for rand_key!

pick_pair()

Alias for rand_pair!

rand_key()

Returns a random key.

      {:one => 1, :two => 2, :three => 3}.pick_key  #~> :three

rand_key!()

Delete a random key-value pair, returning the key.

      a = {:one => 1, :two => 2, :three => 3}
      a.rand_key!  #~> :two
      a            #~> {:one => 1, :three => 3}

rand_pair()

Returns a random key-value pair.

      {:one => 1, :two => 2, :three => 3}.pick  #~> [:one, 1]

rand_pair!()

Deletes a random key-value pair and returns that pair.

      a = {:one => 1, :two => 2, :three => 3}
      a.rand_pair!  #~> [:two, 2]
      a             #~> {:one => 1, :three => 3}

rand_value()

Returns a random hash value.

      {:one => 1, :two => 2, :three => 3}.rand_value  #~> 2
      {:one => 1, :two => 2, :three => 3}.rand_value  #~> 1

rand_value!()

Deletes a random key-value pair and returns the value.

      a = {:one => 1, :two => 2, :three => 3}
      a.at_rand!  #~> 2
      a           #~> {:one => 1, :three => 3}

shuffle()

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}

shuffle!()

Destructive shuffle_hash. Arrange the values in a new random order.

      h = {:a => 1, :b => 2, :c => 3}
      h.shuffle!
      h  #~> {:b=>2, :c=>1, :a=>3}

[Validate]