kumulant

nextBeta

fun Random.nextBeta(alpha: Double, beta: Double): Double(source)

Draw from Beta(alpha, beta) via the two-gamma quotient X / (X + Y) where X ~ Gamma(alpha), Y ~ Gamma(beta). Fast paths for the trivial special cases:

  • alpha == 1.0 && beta == 1.0: returns nextDouble() (Uniform).

  • alpha == 1.0: returns 1 - U^(1/beta) (power distribution).

  • beta == 1.0: returns U^(1/alpha).

nextGamma

Draw from Gamma(alpha, 1) (unit rate). Marsaglia-Tsang (2000) for alpha >= 1 with Stuart's power-of-uniform boost for alpha < 1. Two fast paths for common parameter values:

  • alpha == 1.0: returns -ln(U) directly (Exponential). Bypasses the Gaussian rejection loop entirely.

  • alpha a small positive integer (2..5): sums alpha Exponential samples. Cheaper than one Gaussian + acceptance test at that scale, and the integer check pays for itself in the common Poisson-prior usage pattern.

nextLogNormal

fun Random.nextLogNormal(mean: Double, variance: Double): Double(source)

Draw from a log-normal distribution parameterised by real-scale mean and variance (not the underlying Normal's mu/sigma). Used by log-normal posteriors where the bandit observes positive-valued rewards under a multiplicative noise model.

nextNormal

Float overload of nextNormal; widens to Double, samples, narrows back.


fun Random.nextNormal(mean: Double = 0.0, std: Double = 1.0): Double(source)

Draw from N(mean, std^2) via Marsaglia & Tsang's Ziggurat algorithm. The fast path is one nextInt() + table lookup + comparison; ~97% of draws complete there. The slow path handles the tail beyond R = 3.4426 and the "wedge" regions outside each layer's inner rectangle.

Stateless beyond the Random receiver. The precomputed layer tables (ZIGGURAT_KN, ZIGGURAT_WN, ZIGGURAT_FN) initialise once at class load, so call sites that need many Gaussians can loop on the extension directly.

Reference: Marsaglia, G. & Tsang, W. W. (2000), "The Ziggurat Method for Generating Random Variables", Journal of Statistical Software, 5(8).

nextPoissonOne

Knuth's Poisson sampler at lambda=1; returns 0/1/2/... with mass e^{-1} / k!.