DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
Random Key From Ruby Hash
Returns a random key from your hash, but won't repeat until it's done every one. (I was using this to help quiz myself.)
class Hash
@keys_used = []
def random_key
@keys_used = [] if @keys_used.size == self.size
key = self.keys[rand(self.size)]
while @keys_used.include?(key)
key = self.keys[rand(self.size)]
end
@keys_used << key
return key
end
end





