John von Neumann's First Pseudorandom Number Generator

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 -digit number
2. square it
3. take the middle 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 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."


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


J. von Neumann, "Various Techniques Used in Connection with Random Digits," Monte Carlo Method (A. S. Householder, G. E. Forsythe, and H. H. Germond, eds.), National Bureau of Standards Applied Mathematics Series, 12, Washington, D.C.: U.S. Government Printing Office, 1951, pp. 36–38.
D. Knuth, The Art of Computer Programming, Volume 2: Seminumerical Algorithms, 3rd ed., Cambridge, MA: Addison-Wesley, 1997 pp. 1–193.
    • 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 © 2017 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+