
high G |

Take the number above, and:
1. Square it
2. then find its modulus 377 (i.e. x² mod 377)
note: >modulo operation<
----------
100

thejeff |
This is why actual random number generators are more complex. :)
198 ^ 2 % 377 = 373
26 ^2 / 377 = 1
I think that's actually guaranteed to quickly converge to 1. Since n always smaller than 377, when you divide by 377, the result will always be smaller than your previous n.
The first approach is better, but it's still limited. At best it repeats in less than 377 iterations. Assuming it doesn't hit a break point.
Which, by the way, it didn't:
256^2 = 65536 = 1 - we're dealing with math here, not computers and certainly not 16 bit integers. 32 bit is sufficient, since the biggest we'd need it 376^2.
So we're still at:
256^2 = 65536 % 377 = 315
315^2 % 377 = 74