Middle-square method: Difference between revisions

Content deleted Content added
npov
DanBishop (talk | contribs)
Examples of pathological cases.
Line 6:
 
For a generator of ''n''-digit numbers, the period can be no longer than 10<sup>''n''</sup>. 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).