random - Generating pseudorandom nonrepeating integers from a 32-bit finite set -


i want take set of 4 billion positive integers , output them in pseudorandom sequence, such no number repeated until 4 billion have been outputted. want sequence repeatable , predictable given seed. there algorithm producing such sequence, without resorting putting ordered sequence in memory running pseudorandom sorting operation on entire thing? randomness can weak if makes things easier. thanks

you can use simple linear congruential generator appropriate values a (= 214013), c (= 2531011),m (= 2^32) make full period.

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

this produce all 2^32 values without replacement , repeat same sequence after that.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -