Rust implementation of a fast, discrete, bounded, Zipf-distributed random number generator
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
.
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).