pub fn binomial_distribution<U: UniformGenerator>(
uniform_generator: &mut U,
n: u64,
p: f64,
) -> Result<u64, ErrorsJSL>Expand description
A binomial sample: the number of successes in n independent trials of probability p.
Small n·min(p, 1−p) uses inversion; otherwise Knuth’s recursive beta splitting reduces the
problem exactly: with a = 1 + ⌊n/2⌋, the a-th order statistic of n uniforms is
X ~ Beta(a, n + 1 − a), and the count below p follows from one smaller binomial on the
side of X that contains p. Cost is O(log n) beta samples.