Lably
Skip to content

Pseudorandom number generator

Algorithm that generates an approximation of a random number sequence

  • 11 min read
  • 8 chapters

Related on Lably

Through Algorithm, Randomness and Simulation

PRNGs are central in applications such as simulations (e.g. for the Monte Carlo method), electronic games (e.g. for procedural generation), and cryptography. Cryptographic applications require the output not to be predictable from earlier outputs, and more elaborate algorithms, which do not inherit the linearity of simpler PRNGs, are needed.

Appropriate statistical properties are a central requirement for the output of a PRNG. Careful mathematical analysis is required to have reasonable confidence that a given PRNG generates numbers that are sufficiently close to random to suit the intended use. John von Neumann cautioned about possible misinterpretation of a PRNG as a truly random generator, joking that "Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin."

Potential issues

In practice, the output from many common PRNGs exhibit artifacts that cause them to fail statistical pattern-detection tests. These include:

  • Shorter-than-expected periods for some seed states (such seed states may be called "weak" in this context);
  • Lack of uniformity of distribution for large quantities of generated numbers;
  • Correlation of successive values;
  • Poor dimensional distribution of the output sequence;
  • Distances between where certain values occur are distributed differently from those in a random sequence distribution.

Defects exhibited by flawed PRNGs range from unnoticeable (and unknown) to very obvious. An example was the RANDU random number algorithm used for decades on mainframe computers. It was seriously flawed, but its inadequacy went undetected for a very long time.

In many fields, research work prior to the 21st century that relied on random selection or on Monte Carlo simulations, or in other ways relied on PRNGs, were much less reliable than ideal as a result of using poor-quality PRNGs. Even today, caution is sometimes required, as illustrated by the following warning in the International Encyclopedia of Statistical Science (2010).

The list of widely used generators that should be discarded is much longer [than the list of good generators]. Do not trust blindly the software vendors. Check the default RNG of your favorite software and be ready to replace it if needed. This last recommendation has been made over and over again over the past 40 years. Perhaps amazingly, it remains as relevant today as it was 40 years ago.

As an illustration, consider the widely used programming language Java. Up until 2020, Java still relied on a linear congruential generator (LCG) for its PRNG, which is of low quality (see further below). Java support was upgraded with Java 17.

One well-known PRNG to avoid major problems and still run fairly quickly is the Mersenne Twister (discussed below), which was published in 1998. Other higher-quality PRNGs, both in terms of computational and statistical performance, were developed before and after this date; these can be identified in the List of pseudorandom number generators.

Sign in to keep reading

7 more chapters are free with a Lably account.

More in Computing and communication