On Thu, 11 Nov 2021 13:59:51 GMT, Jim Laskey <jlas...@openjdk.org> wrote:
> The modified ziggurat algorithm is not correctly implemented in > `java.base/jdk/internal/util/random/RandomSupport.java`. > > Create a histogram of a million samples using 2000 uniform bins with the > following range: > Exponential range from 0 to 12. Gaussian range from -8 to 8. > > This does not pass a Chi-square test. If you look at the histogram it is > obviously not showing the shape of the PDF for these distributions. Look > closely at the range around zero (e.g. +/- 0.5). Looks fine. src/java.base/share/classes/jdk/internal/util/random/RandomSupport.java line 1191: > 1189: // At this point, the high-order bits of U1 have not > been used yet, > 1190: // but we need the value in U1 to be positive. > 1191: for (U1 = (U1 >>> 1);; U1 = (rng.nextLong() >>> 1)) { A minor thing, but I would probably write `U1 >>>= 1` instead of `U1 = (U1 >>> 1)`. ------------- Marked as reviewed by bpb (Reviewer). PR: https://git.openjdk.java.net/jdk/pull/6353