in commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/ZigguratSampler.java [607:641]
private double edgeSample(long xx) {
int j = selectRegion();
if (j != 0) {
// Expected overhang frequency = 0.966972
return sampleOverhang(j, xx);
}
// Expected tail frequency = 0.033028 (recursion)
// xx must be discarded as the lower bits have already been used to generate i
// If the tail then exploit the memoryless property of the exponential distribution.
// Perform a new sample and add it to the start of the tail.
// This loop sums tail values until a sample can be returned from the exponential.
// The sum is added to the final sample on return.
double x0 = X_0;
for (;;) {
// Duplicate of the sample() method
final long x = nextLong();
final int i = ((int) x) & 0xff;
if (i < I_MAX) {
// Early exit.
return x0 + X[i] * (x >>> 1);
}
// Edge of the ziggurat
j = selectRegion();
if (j != 0) {
return x0 + sampleOverhang(j, x);
}
// Add another tail sample
x0 += X_0;
}
}