Expand description
A fast generator of discrete, bounded Zipf-distributed random numbers.
For a random variable X
whose values are distributed according to this distribution, the
probability mass function is given by
ⓘ
P(X = k) = H(N,s) * 1 / k^s for k = 1,2,...,N
H(N,s)
is the normalizing constant which corresponds to the generalized harmonic number
of order N
of s
.
Example
use rand::distributions::Distribution;
let mut rng = rand::thread_rng();
let mut zipf = zipf::ZipfDistribution::new(1000, 1.03).unwrap();
let sample = zipf.sample(&mut rng);
This implementation is effectively a direct port of Apache Common’s RejectionInversionZipfSampler, written in Java. It is based on the method described by Wolfgang Hörmann and Gerhard Derflinger in Rejection-inversion to generate variates from monotone discrete distributions from ACM Transactions on Modeling and Computer Simulation (TOMACS) 6.3 (1996).
Structs
- Random number generator that generates Zipf-distributed random numbers using rejection inversion.