class Array

  # Return a random element of the array.
  #
  #   [1, 2, 3, 4].at_rand           #=> 2
  #   [1, 2, 3, 4].at_rand           #=> 4
  #
  def at_rand
    self.at( rand( size ) )
  end

  # Same as #at_rand, but acts in place removing a
  # random element from the array.
  #
  #   a = [1,2,3,4]
  #   a.at_rand!       #=> 2
  #   a                #=> [1,3,4]
  #
  def at_rand!
    return delete_at( Kernel.rand( size ) )
  end

end


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

  require 'test/unit'

  class TCArray < Test::Unit::TestCase

    def test_at_rand
      a = [1,2,3,4,5]
      20.times{ assert_nothing_raised{ a.at_rand } }
      20.times{ assert( a.include?( a.at_rand ) ) }
    end

    def test_at_rand!
      a = ['a','b','c']
      assert_equal( 1, a.at_rand!.length )
      assert_equal( 2, a.length )
    end

  end

=end
