Middle-square method: Difference between revisions

Content deleted Content added
MalafayaBot (talk | contribs)
m robot Adding: zh:平方取中法
m reword
Line 3:
In [[mathematics]], the [[middle-square method]] is a method of generating [[pseudorandom number]]s. 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.
 
To generate a sequence of ten-digit pseudorandom numbers, you would create a ten-digit starting value andis squarecreated itand squared. The middle ten digits of the result would be the next number in the sequence, and returned as the result. YouThis wouldprocess is then squarerepeated that,to andgenerate somore onnumbers.
 
Clearly, 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.