Struct rand_distr::Hypergeometric
source · [−]pub struct Hypergeometric { /* private fields */ }
Expand description
The hypergeometric distribution Hypergeometric(N, K, n)
.
This is the distribution of successes in samples of size n
drawn without
replacement from a population of size N
containing K
success states.
It has the density function:
f(k) = binomial(K, k) * binomial(N-K, n-k) / binomial(N, n)
,
where binomial(a, b) = a! / (b! * (a - b)!)
.
The binomial distribution is the analagous distribution for sampling with replacement. It is a good approximation when the population size is much larger than the sample size.
Example
use rand_distr::{Distribution, Hypergeometric};
let hypergeo = Hypergeometric::new(60, 24, 7).unwrap();
let v = hypergeo.sample(&mut rand::thread_rng());
println!("{} is from a hypergeometric distribution", v);
Implementations
sourceimpl Hypergeometric
impl Hypergeometric
Trait Implementations
sourceimpl Clone for Hypergeometric
impl Clone for Hypergeometric
sourcefn clone(&self) -> Hypergeometric
fn clone(&self) -> Hypergeometric
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for Hypergeometric
impl Debug for Hypergeometric
sourceimpl Distribution<u64> for Hypergeometric
impl Distribution<u64> for Hypergeometric
sourcefn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> u64
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> u64
Generate a random value of T
, using rng
as the source of randomness.
sourcefn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>ⓘNotable traits for DistIter<D, R, T>impl<D, R, T> Iterator for DistIter<D, R, T> where
D: Distribution<T>,
R: Rng, type Item = T;
where
R: Rng,
fn sample_iter<R>(self, rng: R) -> DistIter<Self, R, T>ⓘNotable traits for DistIter<D, R, T>impl<D, R, T> Iterator for DistIter<D, R, T> where
D: Distribution<T>,
R: Rng, type Item = T;
where
R: Rng,
D: Distribution<T>,
R: Rng, type Item = T;
Create an iterator that generates random values of T
, using rng
as
the source of randomness. Read more
impl Copy for Hypergeometric
Auto Trait Implementations
impl RefUnwindSafe for Hypergeometric
impl Send for Hypergeometric
impl Sync for Hypergeometric
impl Unpin for Hypergeometric
impl UnwindSafe for Hypergeometric
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more