Random Number Generation

A random or pseudorandom number generator (RNG) is a computational or physical device designed to generate a random sequence of numbers. There are many different methods for generating random bits and testing their quality. This Demonstration shows all the Mathematica algorithms for producing random binary sequences and random real number sequences (between 0 and 1) with other examples (for binary sequences) that clearly fail as RNGs, such as a repetitive sequence and the Thue-Morse example.
For binary sequences, the Demonstration also includes a sample segment of random bits that was produced by a hardware device whose randomness relies on a quantum physical process and another whose randomness relies on atmospheric noise. It can be seen that all of them succeed or fail the oversimplified tests to detect the lack of randomness, either by changing the seed or by shifting the threshold of the statistical tolerance. All comparisons are made over groups of 10000 bits each (one group per seed) even when only 3000 bits are displayed.


  • [Snapshot]
  • [Snapshot]
  • [Snapshot]
  • [Snapshot]
  • [Snapshot]
  • [Snapshot]


The oversimplified tests include two common statistical tests: normality and autocorrelation. A random sequence is normal (but not the other way around). A normal sequence is a sequence whose digits show a uniform distribution, with all digits being equally likely; the 5-normality test partitions the whole sequence into substrings of length 1 to 5 and tests each for whether the standard variation of their frequency differs by an acceptable value (the statistical tolerance).
The autocorrelation test looks for possible "hidden" functions producing the sequence. It is the cross-correlation of the sequence with itself. Autocorrelation is useful for finding repeating patterns, such as periodic sequences. The oversimplified implementation of this test partitions the entire sequence into groups of 10 and then again into pairs, comparing each first segment with the second, looking for possible regularities.
The compressibility test is based on algorithmic information theory. Compression algorithms look for regularities. If the compressed version of the sequence is short enough compared to the original size of the sequence given a threshold (defined by the tolerance control), the sequence is unlikely to be random.
These tests may be useful as a first step in determining whether or not a generator obviously fails or not as an RNG. No test can prove definitively whether a nontrivial sequence (and the generator that produced it) is good enough as an RNG due to possible random or nonrandom local segments.
    • Share:

Embed Interactive Demonstration New!

Just copy and paste this snippet of JavaScript code into your website or blog to put the live Demonstration on your site. More details »

Files require Wolfram CDF Player or Mathematica.

Mathematica »
The #1 tool for creating Demonstrations
and anything technical.
Wolfram|Alpha »
Explore anything with the first
computational knowledge engine.
MathWorld »
The web's most extensive
mathematics resource.
Course Assistant Apps »
An app for every course—
right in the palm of your hand.
Wolfram Blog »
Read our views on math,
science, and technology.
Computable Document Format »
The format that makes Demonstrations
(and any information) easy to share and
interact with.
STEM Initiative »
Programs & resources for
educators, schools & students.
Computerbasedmath.org »
Join the initiative for modernizing
math education.
Step-by-Step Solutions »
Walk through homework problems one step at a time, with hints to help along the way.
Wolfram Problem Generator »
Unlimited random practice problems and answers with built-in step-by-step solutions. Practice online or make a printable study sheet.
Wolfram Language »
Knowledge-based programming for everyone.
Powered by Wolfram Mathematica © 2018 Wolfram Demonstrations Project & Contributors  |  Terms of Use  |  Privacy Policy  |  RSS Give us your feedback
Note: To run this Demonstration you need Mathematica 7+ or the free Mathematica Player 7EX
Download or upgrade to Mathematica Player 7EX
I already have Mathematica Player or Mathematica 7+