Below is a Python code that calculates the periodicity of the middle-square method for a given 4 digit-numbers:
n = int(input("Please enter a four digit number: ")) already_seen = list() while n not in already_seen: already_seen.append(n) n = int(str(n * n).zfill(8)[2:6]) print(n) print('periodicity = ', len(already_seen) - already_seen.index(n))
For example the seed number 9267 yield to a series that enters in a short loop of periodicity 4 [9267, …, 6100, 2100, 4100, 8100, 6100, 2100, 4100, 8100, 6100, ...]
Is there any solution to find out what numbers yield to the longest periodicity without having to simulate? If no, why isn't there a solution? Generally speaking, are there solutions to find out the periodicity of a given seed in different random number generators?