Return to Snippet

Revision: 3993
at October 15, 2007 01:22 by chrisaiv


Initial Code
#A. Create a Hash
hash = {:key1 => "item1", :key2 => "item2", :key3 => "item3"}
#B. Return a new array of all the Values from the Hash
items = hash.values
#C. Randomly 
puts items[rand(items.length)]

Initial URL

                                

Initial Description
Needed a way to randomly select an item from within a Hash

Initial Title
Ruby: Randomly selecting an item from within a Hash

Initial Tags

                                

Initial Language
Ruby