3 ms·
Any reason for the down-vote? I honestly want to learn.
by Yrlec 15y ago
Any reason for the down-vote? I honestly want to learn.
- gcp 15y agoThe Java Random class uses a 48-bit LCG with a 35-bit multiplier. Because of this, small seed values won't be able to "wrap around" the full range of the LCG and will cause starting sequences that are all but random relative to each other. Put differently, you're seeing that 35/48 = 0.73. I'd consider this a bug in Java, but it's a common one. Qt has the same problem. Could have been avoided by cycling the seed through the LCG once, instead of using XOR.
- Yrlec 15y agoInteresting, thanks! Any particular reason they limit the multiplier to 35 bits and the output to 48 bits? Edit: just noticed that Java limits the output to 32 bits, not 48 (http://en.wikipedia.org/wiki/Linear_congruential_generator http://en.wikipedia.org/wiki/Linear_congruential_generator). How does it create 64 bit values, like long and double?
- marshray 15y agoProbably it generates 32 bits twice.
- gcp 15y agoAny particular reason they limit the multiplier to 35 bits and the output to 48 bits? Good question. There appears to be no good justification for this, but the generator is guaranteed by the docs. So it's possible the initial implementation was bad and everybody is required to follow it since.