Generate a pseudo random, predictable non-repeating integer sequence purely mathematically.

random

Let's say I have a range of integer values (could be anything but let's choose 1000000 to 9999999).

I want to begin by choosing a number somewhere within that range. I really don't care which one, it could be the first, last or random.

From that point on, I want to feed the last number retrieved into a formula that returns a new pseudo-random – or just "not obviously in sequence" – number within the specified range that won't repeat for at least N calls, with N being preferably a very very high number or even until all numbers in the range have been emitted.

I don't want to have to store all of the previously retrieved values other than the last one.

The sequence does not have to be particularly random, it just has to appear so to a human, and it would be advantageous if it was predictable (and repeatable) with the same range/start number.

Is that possible?

I've put this here instead of a programming forum as I have no idea if this is mathematically possible, and thought this the best place to ask.

EDIT 1 –
I am not a mathematician, clearly. I have read a few articles on various PRNGs but the maths is just too heavy for me to even assess if they apply.

I guess I need someone to point me somewhere and say "That will do what you want" and I can then read it and try to understand it knowing it's what I need.

Best Answer

A Linear Congruential Generator seems to fit all of your needs. Note that the typical formulation generates numbers in the range $[0,N]$ but of course it is trivial to shift the numbers to any desired interval.

Note in particular the theorem by Hull and Dobell on how to pick the multiplicative and additive constants so that the LCG generates all numbers in the interval before repeating.

Related Question