WOLFRAM|DEMONSTRATIONS PROJECT

John von Neumann's First Pseudorandom Number Generator

​
sequence length
10
iterations
1
seed
random
seed state:
middle-square generated sequences:
Pseudorandom number generators have applications in many areas: simulation, game-playing, cryptography, statistical sampling, evaluation of multiple integrals, and computations in statistical physics, to name a few.
The method illustrated in this Demonstration, known as the middle-square method, is a generalization of the first computer-based pseudorandom number generator (PRNG). John von Neumann suggested it in 1946 for the purpose of devising, together with Stan Ulam, what would later become known as the Monte Carlo method for the simulation of physical processes, motivated by their work at Los Alamos National laboratory while building the atomic bomb.
Iterating von Neumann's procedure produces a series of numbers generated by a deterministic process intended merely to imitate a random sequence. The procedure is very simple:
1. take any
n
-digit number
2. square it
3. take the middle
n
digits of the resulting number as the "random number"
4. use that number as the seed for the next iteration
Of course there are at most only
n
10
different numbers, so eventually the whole sequence repeats in the same order and eventually a number comes up that was squared before. Another flaw is when the sequence reaches 000…, from which all squares from then on are 0 and the resulting sequences (after padding) are also 0. In other words, the method eventually reaches a fixed point. One way to avoid this is to pad with 1s rather than 0s, as was done in this Demonstration.
Each iteration starts from a random seed and produces a sequence of sequences of numbers generating the grid shown. The irregularity of the grid shows that the procedure succeeds in producing a random-looking output in spite of the simplicity and deterministic nature of the procedure.
John von Neumann himself joked about it: "Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin."