Code Golf: MSM Random Number Generator
- by Vivin Paliath
The challenge
The shortest code by character count that will generate (pseudo)random numbers using the Middle-Square Method.
The Middle-Square Method of (pseudo)random number generation was first suggested by John Von Neumann in 1946 and is defined as follows:
Rn+1 = mid((Rn)2, m)
For example:
34562 = 11943936
mid(11943936) = 9439
94392 = 89094721
mid(89094721) = 0947
9472 = 896809
mid(896809) = 9680
96802 = 93702400
mid(93702400) = 7024
Test cases:
A seed of 8653 should give the following numbers (first 10):
8744, 4575, 9306, 6016, 1922, 6940, 1636, 6764, 7516, 4902