class Hash

  # Returns a random key.
  #
  #   {:one => 1, :two => 2, :three => 3}.pick_key  #=> :three
  #
  def rand_key
    keys.at( rand(keys.size) )
  end

  # Delete a random key-value pair, returning the key.
  #
  #   a = {:one => 1, :two => 2, :three => 3}
  #   a.pick_key!  #=> :two
  #   a            #=> {:one => 1, :three => 3}
  #
  def rand_key!
    k,v = rand_pair
    delete( k )
    return k
  end

  alias_method( :pick_key, :rand_key! )

end


#  _____         _
# |_   _|__  ___| |_
#   | |/ _ \/ __| __|
#   | |  __/\__ \ |_
#   |_|\___||___/\__|
#
=begin test

  require 'test/unit'

  class TCHash < Test::Unit::TestCase

    def test_rand_key
      h = { :a=>1, :b=>2, :c=>3 }
      10.times { assert( h.keys.include?( h.rand_key ) ) }
    end

  end

=end
