Generating pseudo-random non-repeating integers from a 32-bit finite set

I want to take a set of 4 billion positive integers and print them in a pseudo-random sequence so that the number does not repeat until all 4 billion are deduced. I want this sequence to be repeatable and predictable for a given seed. Is there a good algorithm for creating such a sequence without resorting to placing an ordered sequence in memory, and then performing a pseudo-random sorting operation on the whole subject? Randomness can be very weak if it makes the situation easier. Thanks

+3
source share
1 answer

You can use a simple linear congruential generator with the corresponding values for a (= 214013), c (= 2531011), m (= 2^32)to make it complete.

X(n+1) = (a*X(n) + c) mod m

This will get all 2 ^ 32 values ​​without replacement and repeat the same sequence after that.

+1
source

All Articles