pub struct Zeta<F>{ /* private fields */ }Expand description
The Zeta distribution Zeta(s).
The Zeta distribution
is a discrete probability distribution with parameter s.
It is a special case of the Zipf distribution with n = ∞.
It is also known as the discrete Pareto, Riemann-Zeta, Zipf, or Zipf–Estoup distribution.
§Density function
f(k) = k^(-s) / ζ(s) for k >= 1, where ζ is the
Riemann zeta function.
§Plot
The following plot illustrates the zeta distribution for various values of s.
§Example
use rand::prelude::*;
use rand_distr::Zeta;
let val: f64 = rand::rng().sample(Zeta::new(1.5).unwrap());
println!("{}", val);§Integer vs FP return type
This implementation uses floating-point (FP) logic internally, which can
potentially generate very large samples (exceeding e.g. u64::MAX).
It is safe to cast such results to an integer type using as
(e.g. distr.sample(&mut rng) as u64), since such casts are saturating
(e.g. 2f64.powi(64) as u64 == u64::MAX). It is up to the user to
determine whether this potential loss of accuracy is acceptable
(this determination may depend on the distribution’s parameters).
§Notes
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
Fof the actual sample. - to prevent infinite loops for very small
s.
§Implementation details
We are using the algorithm from Non-Uniform Random Variate Generation, Section 6.1, page 551.
Implementations§
Trait Implementations§
Source§impl<F> Distribution<F> for Zeta<F>
impl<F> Distribution<F> for Zeta<F>
impl<F> Copy for Zeta<F>
impl<F> StructuralPartialEq for Zeta<F>
Auto Trait Implementations§
impl<F> Freeze for Zeta<F>where
F: Freeze,
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
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<D, T> DistributionExt<T> for Dwhere
D: Distribution<T>,
impl<D, T> DistributionExt<T> for Dwhere
D: Distribution<T>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.