# 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.

See the binomial distribution for the analogous distribution for sampling with replacement. It is a good approximation when the population size is much larger than the sample size.

## §Density function

`f(k) = binomial(K, k) * binomial(N-K, n-k) / binomial(N, n)`

,
where `binomial(a, b) = a! / (b! * (a - b)!)`

.

## §Plot

The following plot of the hypergeometric distribution illustrates the probability of drawing
`k`

successes in `n = 10`

draws from a population of `N = 50`

items, of which either `K = 12`

or `K = 35`

are successes.

## §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§

## Trait Implementations§

source§### impl Clone for Hypergeometric

### impl Clone for Hypergeometric

source§#### fn clone(&self) -> Hypergeometric

#### fn clone(&self) -> Hypergeometric

Returns a copy of the value. Read more

1.0.0 · source§#### fn clone_from(&mut self, source: &Self)

#### fn clone_from(&mut self, source: &Self)

Performs copy-assignment from

`source`

. Read moresource§### impl Debug for Hypergeometric

### impl Debug for Hypergeometric

source§### impl<'de> Deserialize<'de> for Hypergeometric

### impl<'de> Deserialize<'de> for Hypergeometric

source§#### fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,

#### fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more

source§### impl Distribution<u64> for Hypergeometric

### impl Distribution<u64> for Hypergeometric

source§### impl PartialEq for Hypergeometric

### impl PartialEq for Hypergeometric

source§### impl Serialize for Hypergeometric

### impl Serialize for Hypergeometric

### impl Copy for Hypergeometric

### impl StructuralPartialEq for Hypergeometric

## Auto Trait Implementations§

### impl Freeze for Hypergeometric

### impl RefUnwindSafe for Hypergeometric

### impl Send for Hypergeometric

### impl Sync for Hypergeometric

### impl Unpin for Hypergeometric

### impl UnwindSafe for Hypergeometric

## 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

source§### impl<T> CloneToUninit for Twhere
T: Clone,

### impl<T> CloneToUninit for Twhere
T: Clone,

source§#### unsafe fn clone_to_uninit(&self, dst: *mut T)

#### unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (

`clone_to_uninit`

)