The old proposal for Sun

When this problem was reported to Sun, they originally said they would try to address the issue.

I proposed that they use code like:

public synchronized int nextInt() {

 seed = (seed & mask) * multiplier + addend + (seed >>> 47);
 return (int) (seed >>> 16);
} replace code like...
public synchronized int nextInt() {

 seed = (seed & mask) * multiplier + addend;
 return (int) (seed >>> 16);

Unfortunately, it turns out that Sun's idea of fixing the problem involved introducing new methods for generating random boolean values and the like, retaining backwards compatibility with the old code. Consequently, the central problem remains.

Sun's method uses a 48 bit seed and (as far as the bottom bit is concerned) only accesses 17 bits of this - producing extremely severe non-randomness.

The above method retains all 64 bits of the seed. Each bit can affect every other bit - in sharp contrast to the original algorithm.

Highly random top bits are shifted by the largest prime number less than 48 and added to the original, ensuring that no bits experience limited periodicity due to receiving influence only from bits of lesser significance than them.

This method effectively eliminates the problem concerning poor performance in the low bits, without any loss of randomness elsewhere, or any particular performance hit.

Return to the main page.

For links to other Java-related sites try here.

Please direct any queries concering this page to Tim Tyler.