in commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/ZigguratNormalizedGaussianSampler.java [131:164]
private double fix(long hz,
int iz) {
if (iz == 0) {
// Base strip.
// This branch is called about 2.55224E-4 times per sample.
double y;
double x;
do {
// Avoid infinity by creating a non-zero double.
// Note: The extreme value y from -Math.log(2^-53) is (to 4 sf):
// y = 36.74
// The largest value x where 2y < x^2 is false is sqrt(2*36.74):
// x = 8.571
// The extreme tail is:
// out = +/- 12.01
// To generate this requires longs of 0 and then (1377 << 11).
y = -Math.log(InternalUtils.makeNonZeroDouble(rng.nextLong()));
x = -Math.log(InternalUtils.makeNonZeroDouble(rng.nextLong())) * ONE_OVER_R;
} while (y + y < x * x);
final double out = R + x;
return hz > 0 ? out : -out;
}
// Wedge of other strips.
// This branch is called about 0.0146584 times per sample.
final double x = hz * W[iz];
if (F[iz] + rng.nextDouble() * (F[iz - 1] - F[iz]) < pdf(x)) {
// This branch is called about 0.00797887 times per sample.
return x;
}
// Try again.
// This branch is called about 0.00667957 times per sample.
return sample();
}