8215441: Increase uniformity of the distribution of BigIntegers constructed by BigInteger(int, Random)
Brian Burkhalter
brian.burkhalter at oracle.com
Thu Dec 20 17:08:04 UTC 2018
Thanks for the comments. It looks like I got this completely wrong. For some reason I was thinking that the distribution of bit lengths should be uniform which is patently incorrect. Consider the example of a four bit integer. The possible values are
1111 1110 1101 1100 1011 1010 1001 1000
0111 0110 0101 0100
0011 0010
0001
0000
Half of the values have bit length 4, 25% have bit length 2, etc. Re-running my test code shows pretty much this sort of distribution of the bit lengths. It looks like the likelihood of bit lengths from the largest length downward is a geometric sequence with initial value 0.5 for the largest bit length and common ratio 0.5. So I concur with Adam that the current implementation looks correct. Therefore I think that [1] should be withdrawn and [2] closed as not an issue.
Thanks,
Brian
[1] https://bugs.openjdk.java.net/browse/JDK-8215441
[2] https://bugs.openjdk.java.net/browse/JDK-8146153
More information about the core-libs-dev
mailing list