I’m building a hash that has 100 items and I also have a random number generator that generates 100 random values between 0 and 100.
I want to iterate through my numbers, 0..100 in consecutive order and assign them to the keys of the hash.
Then I want to iterate through the 100 random numbers and assign them to the values of the hash.
hash = {}
(0..100).each {|e| puts e} #just prints out the values
@numbers = 100.times.map{ 0+Random.rand(0..100)}
That’s what I’ve got so far. Any help would be much appreciated. Thanks!
The first line will initialize the empty hash (as you did above). The second line assigns 0 to 99 as keys to the hash, and random values between 0 and 100.
timesis a method belonging to the Integer class. Given a block, it will pass in each successive integerntimes.