While making a map generator in Java I found a rather unnerving problem with their random number generator, to specify, when two RNGs have very similar seeds (differing in small integers) their first output value will become very similar!
Example code:
Random r = new Random();
long n = 100000; //Choose any number
r.setSeed(n);
System.out.println(r.nextInt());
r.setSeed(n+1);
System.out.println(r.nextInt());
This pretty much broke my faith in the original Java RNG, since I use coordinates to seed a map generator.
Could someone suggest either a redefinition for the Random.next(int bits) method, or some other fix for this problem?
Thank you for your help!
did you compare the sequence of the first ~20 values you get from 100000 and 100001?
these are the first 20 nextInts of seeds 100000 and 100001 resp. with in the third column the amount of different bits (bitcount of the xor between the 2)
this last column should remain around 16
not so similar after 3-5 iterations he
besides the standard Random implements a linear congruential RNG which is known not to be the best pseudo-random implementation in existence but the most efficient with memory (only one 64bit word for a period of
2^48)for the interested the multiplier is
0x5deece66dLand c is0xbL