Generating Random Numbers in Ruby: rand, Random & SecureRandom
To generate a random number in Ruby, call rand: rand(10) returns an integer from 0–9, rand(1..10) an integer from 1–10, and rand alone a float between 0.0 and 1.0. For security-sensitive values like tokens and passwords, use SecureRandom — rand is predictable. Computers cannot produce truly random numbers by computation alone. A deterministic machine can only produce pseudorandom numbers: a stream that looks random but comes from an algorithm fed with a starting value, the seed.