No computer can generate truly random numbers purely by computation. The best they can do is to generate pseudorandom numbers, which are a sequence of numbers that appear random but are not.

To a human observer, these numbers are indeed random. There will be no short repeating sequences, and, at least to the human observer, they'll present no clear pattern. However, given enough time and motivation, the original seed can be discovered, the sequence recreated and the next number in the sequence guessed.

For this reason, the methods discussed in this article should probably not be used to generate numbers that must be cryptographically secure.

Pseudorandom number generators must be seeded in order to produce sequences that differ each time a new random number is generated. No method is magical — these seemingly random numbers are generated using relatively simple algorithms and relatively simple arithmetic. By seeding the PRNG, you're starting it off at a different point every time. If you didn't seed it, it would generate the same sequence of numbers each time.

In Ruby, the Kernel#srand method can be called with no arguments. It will choose a random number seed based on the time, the process ID and a sequence number. Simply by calling srand anywhere at the beginning of your program, it will generate a different series of seemingly random numbers each time you run it. This method is called implicitly when the program starts up, and seeds the PRNG with the time and process ID (no sequence number).