This Ruby example page generates random numbers with the rand method. It uses srand to seed a random stream of numbers. It's often useful in games, simulation and unit testing to generate random numbers. Ruby provides easy access to a pseudo- random number. How do I generate a random number between 0 and n? What is wrong with rand(range)? From Ruby Random Numbers: If you needed a.