You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i.e. a multiplier of 69621, increment 0, and modulus 0x7FFFFFFF, which was referred by Knuth as "Park and Miller generator nr. 3". Perhaps that would have a better randomness?
In the current implementation, lowest two bits of the rand() result are always either 00/11 or 01/10 depending on the starting seed.
the following code produces an endless stream of either 0 3 0 3 0 3 0 3... or 1 2 1 2 1 2 1 2...:
srand(time(NULL));
while(1)
printf("%d\n", rand() % 4);
This happens because the multiplier does not follow the proper conditions of a good Linear congruential generator (rule #3 is violated):
http://en.wikipedia.org/wiki/Linear_congruential_generator#Period_length
The text was updated successfully, but these errors were encountered: