Note: You are viewing an old revision of this page. View the current version.

A RandomNumberGenerator is either a piece of hardware or software that generates random numbers in the widest sense. A good one is crucial to applications in Cryptography: if an attacker can guess the sequence of "random" numbers used to generate keys or other variables for your algorithm, he gets an important foot in the door for cracking your communication -- or can even walk right in. There are many different approaches for RandomNumberGenerators, however, the biggest distinction is between true vs pseudorandom number generators.

True random number generators

These must be hardware by definition. A variety of approaches for their design exist, but listening to white noise or radioactive decay seem to be the most popular ones. There are a number of publicly queriable true random number generators on the web, such as and

Pseudorandom number generators

A pseudo random number generator such as offered by the random(3) and rand(3) functions of the standard C library generates numbers using mathematical Algorithms.

Anyone attempting to produce random numbers by purely arithmetic means is, of course, in a state of sin. --JohnVonNeumann

An inevitable consequence is that such a generator has a "period", which means that it produces a repeating sequence of numbers. With a good algorithm though, the period length can well reach billions of numbers.

However, designing such an algorithm is difficult terrain which requires thorough understanding of statistics and very sharp math skills. Do not attempt to roll your own. Most naive attempts at handrolled pseudorandom number generators have alarmingly short period lengths. Often, hapless programmers will try to make a "better" generator by lumping together two different algorithms with decent period lengths each -- but the result is almost invariably a generator with a shorter period!

Another problem in cryptographical applications of pseudorandom numbers is that the algorithm is known. If you know a long enough sequence of generated numbers, you can simply solve the resulting equations yourself and then predict the numbers the generator will be producing next. There is an obvious solution: the algorithm must include enough hidden state so that a solvable set of equations cannot be formulated just by looking at a number sequence it generated.

But note that true randomness still is not always desirable. Random number sequences often have certain specific characteristics which make them better suited as input to certain kinds of statistical algorithm, because they cause a far faster convergence toward the same final result than truly random numbers could. Truly random numbers also make debugging much harder for obvious reasons; if you want to verify an algorithm, you want to be able to replay "random" number sequences as necessary. On the other hand, you will usually need a statistically decently random sequence to examine the longterm behaviour of the algorithm, so just using a sequence with regular characteristics wouldn't work.

So there are many areas where pseudorandom numbers are actually more desirable than truly random ones.


In Unix systems, there's commonly a /dev/random device to access a pseudorandom number generator. This generator however includes a twist that lets it generate higher quality random numbers than otherwise expected: its seed is periodically perturbed using using low-level timing information from the network, mouse, keyboard, and possibly other entropy sources, which only the Kernel has proper access to. It is generally considered a sufficiently good generator for everything except the random numbers to be used in cryptographic suituations PublicKey generation.