Struct rand_distr::Zeta
source · pub struct Zeta<F>where
F: Float,
Standard: Distribution<F>,
OpenClosed01: Distribution<F>,{ /* private fields */ }
Expand description
Samples integers according to the zeta distribution.
The zeta distribution is a limit of the Zipf
distribution. Sometimes it
is called one of the following: discrete Pareto, Riemann-Zeta, Zipf, or
Zipf–Estoup distribution.
It has the density function f(k) = k^(-a) / C(a)
for k >= 1
, where a
is the parameter and C(a)
is the Riemann zeta function.
Example
use rand::prelude::*;
use rand_distr::Zeta;
let val: f64 = thread_rng().sample(Zeta::new(1.5).unwrap());
println!("{}", val);
Remarks
The zeta distribution has no upper limit. Sampled values may be infinite. In particular, a value of infinity might be returned for the following reasons:
- it is the best representation in the type
F
of the actual sample. - to prevent infinite loops for very small
a
.
Implementation details
We are using the algorithm from Non-Uniform Random Variate Generation, Section 6.1, page 551.
Implementations§
source§impl<F> Zeta<F>where
F: Float,
Standard: Distribution<F>,
OpenClosed01: Distribution<F>,
impl<F> Zeta<F>where F: Float, Standard: Distribution<F>, OpenClosed01: Distribution<F>,
Trait Implementations§
source§impl<F> Clone for Zeta<F>where
F: Float + Clone,
Standard: Distribution<F>,
OpenClosed01: Distribution<F>,
impl<F> Clone for Zeta<F>where F: Float + Clone, Standard: Distribution<F>, OpenClosed01: Distribution<F>,
source§impl<F> Debug for Zeta<F>where
F: Float + Debug,
Standard: Distribution<F>,
OpenClosed01: Distribution<F>,
impl<F> Debug for Zeta<F>where F: Float + Debug, Standard: Distribution<F>, OpenClosed01: Distribution<F>,
source§impl<F> Distribution<F> for Zeta<F>where
F: Float,
Standard: Distribution<F>,
OpenClosed01: Distribution<F>,
impl<F> Distribution<F> for Zeta<F>where F: Float, Standard: Distribution<F>, OpenClosed01: Distribution<F>,
source§fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> F
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> F
Generate a random value of
T
, using rng
as the source of randomness.impl<F> Copy for Zeta<F>where F: Float + Copy, Standard: Distribution<F>, OpenClosed01: Distribution<F>,
Auto Trait Implementations§
impl<F> RefUnwindSafe for Zeta<F>where F: RefUnwindSafe,
impl<F> Send for Zeta<F>where F: Send,
impl<F> Sync for Zeta<F>where F: Sync,
impl<F> Unpin for Zeta<F>where F: Unpin,
impl<F> UnwindSafe for Zeta<F>where F: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more