I’m fairly new to coding ruby and I’m using “Learn to program” by Chris
Pine.
After taking a look at the ‘rand’ method, I’m introduced to ‘srand’ and
here’s what I’m confused about…
srand(123)
puts rand(100)
puts rand(100)
…will give me 2 random numbers which will repeat themselves for as
many times as the program is run but according to the book “If you want
to get different numbers again (like what happens if you
never use srand), then just call srand(0).” I don’t understand what it
means cos this is what I tried…
srand(0)
puts rand(100)
puts rand(100)
…and only the first 2 numbers changed after it was run again and they
kept repeating every time it is run. what exactly does the book mean and
how is it written in code?