pub fn poisson_distribution_knuth<U>(
uniform_generator: &mut U,
lambda: f64,
) -> f64where
U: UniformGenerator,Expand description
A Poisson(lambda) sample (returned as f64), for lambda ≥ 0.
Small λ (below 16) uses Knuth’s multiplication method, a fresh uniform per step. Larger λ
use the exact recursion of Ahrens and Dieter (Knuth, TAOCP 3.4.1): with m = ⌊7λ/8⌋ and
G ~ Gamma(m, 1) (the time of the m-th event of a unit-rate Poisson process), the count is
m + Poisson(λ − G) if G < λ, and Binomial(m − 1, λ/G) otherwise, so the cost grows only
logarithmically in λ. (An earlier version reused one uniform throughout, with its loop
condition inverted, and returned −1 for every λ.) Returns NaN for negative or NaN λ.