Middle-square method: Difference between revisions

Content deleted Content added
Tag: Reverted
Restoring revision 1153973214 by Nagol0929: Vandalism (RW 16.1)
Line 6:
== History ==
===In mathematics===
The method was not invented by [[John von Neumann]], and was not described by him at a conference in 1949.<ref name="vonneumann">The 1949 papers were not reprinted until 1951. John von Neumann, “Various techniques used in connection with random digits”, in A.&nbsp;S. Householder, G.&nbsp;E. Forsythe, and H.&nbsp;H. Germond, eds., ''Monte Carlo Method, National Bureau of Standards Applied Mathematics Series'', vol.&nbsp;12 (Washington, D.C.: U.S. Government Printing Office, 1951): pp.&nbsp;36–38.</ref>
 
In the 1949 talk, Von Neumann quipped that "Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin." What he meant, he elaborated, was that there were no true "random numbers", just means to produce them, and "a strict arithmetic procedure", like the middle-square method, "is not such a method". Nevertheless, he found these methods hundreds of times faster than reading "truly" random numbers off [[punch cards]], which had practical importance for his [[ENIAC]] work. He found the "destruction" of middle-square sequences to be a factor in their favor, because it could be easily detected: "one always caca the appearance of undetected short cycles".<ref name="vonneumann"/> [[Nicholas Metropolis]] reported sequences of 750,000 digits before "destruction" by means of using 38-bit numbers with the "middle-square" method.<ref>Donald E. Knuth, ''The art of computer programming, Vol.&nbsp;2, Seminumerical algorithms'', 2nd edn. (Reading, Mass.: Addison-Wesley, 1981), ch.&nbsp;3, section&nbsp;3.1.</ref>
Line 30:
 
while number not in already_seen:
counter -+= 1
already_seen.add(number)
number = int(str(number * number).zfill(8)[2:6]) # zfill adds padding of zeroes