Middle-square method

This is an old revision of this page, as edited by DanBishop (talk | contribs) at 05:07, 18 June 2009 (Examples of pathological cases.). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

In mathematics, the middle-square method is a method of generating pseudorandom numbers. In practice it is not a good method, since its period is usually very short and it has some crippling weaknesses. The method was first suggested by John Von Neumann in 1946.

One iteration of the middle-square method, showing a six digit seed, which is then squared, and the resulting value has its middle six digits as the output value (and also as the next seed for the sequence).

To generate a sequence of ten-digit pseudorandom numbers, a ten-digit starting value is created and squared. The middle ten digits of the result would be the next number in the sequence, and returned as the result. This process is then repeated to generate more numbers.

For a generator of n-digit numbers, the period can be no longer than 10n. If the middle ten digits are all zeroes, the generator then outputs zeroes forever. If the first half of a number in the sequence is zeroes, the subsequent numbers will be decreasing to zero. While these runs of zero are easy to detect, they occur too frequently for this method to be of practical use.

The middle-squared method can also get stuck on a number other than zero. For n=4, this occurs with the values 0100, 2500, 3792, and 7600. Other seed values form very short repeating cycles, e.g., 0540-2916-5030-3009.

Von Neumann was aware of these problems, but for his purposes the middle-square method was quick (important for use on the ENIAC), and its errors were easy to detect (when it failed, it generally failed spectacularly).

See also