pub struct Binomial { /* private fields */ }Expand description
The binomial distribution Binomial(n, p).
The binomial distribution is a discrete probability distribution
which describes the probability of seeing k successes in n
independent trials, each of which has success probability p.
§Density function
f(k) = n!/(k! (n-k)!) p^k (1-p)^(n-k) for k >= 0.
§Plot
The following plot of the binomial distribution illustrates the
probability of k successes out of n = 10 trials with p = 0.2
and p = 0.6 for 0 <= k <= n.
§Example
use rand_distr::{Binomial, Distribution};
let bin = Binomial::new(20, 0.3).unwrap();
let v = bin.sample(&mut rand::rng());
println!("{} is from a binomial distribution", v);§Numerics
The implementation uses f64 internally, which leads to rounding errors for big numbers.
For very large samples (> 2^53) the least significant bits of the output will not be random.
This means that something like bin.sample(&mut rand::rng()) % 4 will not follow the correct distribution.
The more significant bits should be correctly distributed.