# Calculating periodicity of a pseudo random number generator (Middle-square method) [closed]

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: "))
n = int(str(n * n).zfill(8)[2:6])
print(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?

-

## migration rejected from scicomp.stackexchange.comJul 24 '14 at 20:22

This question came from our site for scientists using computers to solve scientific problems. Votes, comments, and answers are locked due to the question being closed here, but it may be eligible for editing and reopening on the site where it originated.

## closed as off-topic by fgrieu, otus, Gilles, e-sushi♦, archieJul 24 '14 at 20:22

• This question does not appear to be about cryptography within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

On the other hand, a question about which random number generator to use for a particular purpose in scientific computing would be on-topic. What do you need the random numbers for, and why do you care about periodicity? – Christian Clason Jul 24 '14 at 7:33
I was just curious $\ddot \smile \space$ There is no application behind my question! – Remi.b Jul 24 '14 at 7:34
This question is squarely off-topic on crypto.SE because it is about a non-cryptographic Random Number Generator. – fgrieu Jul 24 '14 at 18:54