public double sample()

in commons-rng-sampling/src/main/java/org/apache/commons/rng/sampling/distribution/AhrensDieterMarsagliaTsangGammaSampler.java [161:190]


        public double sample() {
            // [1]: p. 228, Algorithm GS.

            while (true) {
                // Step 1:
                final double u = rng.nextDouble();
                final double p = bGSOptim * u;

                if (p <= 1) {
                    // Step 2:
                    final double x = Math.pow(p, oneOverAlpha);
                    final double u2 = rng.nextDouble();

                    if (u2 > Math.exp(-x)) {
                        // Reject.
                        continue;
                    }
                    return theta * x;
                }

                // Step 3:
                final double x = -Math.log((bGSOptim - p) * oneOverAlpha);
                final double u2 = rng.nextDouble();

                if (u2 <= Math.pow(x, alpha - 1)) {
                    return theta * x;
                }
                // Reject and continue.
            }
        }