in commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/StableSampler.java [1060:1098]
public double sample() {
final double phiby2 = getPhiBy2();
final double w = getOmega();
// Compute some tangents
final double a = phiby2 * SpecialMath.tan2(phiby2);
final double b = eps * phiby2 * SpecialMath.tan2(eps * phiby2);
// Compute some necessary subexpressions
final double da = a * a;
final double db = b * b;
final double a2 = 1 - da;
final double a2p = 1 + da;
final double b2 = 1 - db;
final double b2p = 1 + db;
// Compute coefficient.
final double z = a2p * b2 / (w * a2 * b2p);
// Compute the exponential-type expression
final double alogz = Math.log(z);
final double d = SpecialMath.d2(epsDiv1mEps * alogz) * (alogz * inv1mEps);
// Pre-compute the multiplication factor.
// The numerator may be zero. The denominator is not zero as a2 is bounded to
// above zero when the uniform deviate that generates phiby2 is not 0 or 1.
final double f = (2 * ((a - b) * (1 + a * b))) / (a2 * b2p);
// Compute the stable deviate:
final double x = (1 + eps * d) * f;
// Test the support
if (LOWER < x && x < UPPER) {
return x;
}
// Error correction path.
// Here we use the formula provided by Weron which is easier to correct
// when deviates are extreme or alpha -> 0.
return createSample(phiby2 * 2, w);
}