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
Post a Comment