I have been trying to research the middle square method as a way to generate pseudo-random numbers for a school project. Everywhere I look claims that this method is limited by its short period and will either loop or repeat if used enough times. However, I don't really understand how this happens or even why it happens. I wrote a Python script that takes a seed of 6 digits and I have yet to witness any looping or repetition. Is this because my seed is too large? If so, what digit seed would be appropriate to show the limitations of this method? Lastly, why does this method apparently repeat or loop if done enough times? Thank you!
2026-03-30 06:45:55.1774853155
The limitations of the middle square method in generating pseudo-random numbers.
1.2k Views Asked by Bumbble Comm https://math.techqa.club/user/bumbble-comm/detail At
2
Since your internal state has a fixed size (it's an $n$-digit number), there are only finitely many ($10^n$) possible states, so if you iterate enough ($10^n+1$ times) you'll inevitably repeat an internal state. Since the method is deterministic, the sequence will repeat from that point onward. This is true of all PRNG algorithms, but good ones have internal states much larger than the numbers being generated. (E.g. using a 10-digit state while only outputting the last 5 digits of each state in order to generate 5-digit numbers is better than using a 5-digit state.) You should be able to explore these ideas (with sufficiently small seeds) using your Python script.