# Struct rand_distr::Binomial

source · `pub struct Binomial { /* private fields */ }`

## Expand description

The binomial distribution `Binomial(n, p)`

.

The binomial distribution is a discrete probability distribution
which describes the probability of seeing `k`

successes in `n`

independent trials, each of which has success probability `p`

.

## §Density function

`f(k) = n!/(k! (n-k)!) p^k (1-p)^(n-k)`

for `k >= 0`

.

## §Known issues

See documentation of `Binomial::new`

.

## §Plot

The following plot of the binomial distribution illustrates the
probability of `k`

successes out of `n = 10`

trials with `p = 0.2`

and `p = 0.6`

for `0 <= k <= n`

.

## §Example

```
use rand_distr::{Binomial, Distribution};
let bin = Binomial::new(20, 0.3).unwrap();
let v = bin.sample(&mut rand::thread_rng());
println!("{} is from a binomial distribution", v);
```

## Implementations§

source§### impl Binomial

### impl Binomial

source#### pub fn new(n: u64, p: f64) -> Result<Binomial, Error>

#### pub fn new(n: u64, p: f64) -> Result<Binomial, Error>

Construct a new `Binomial`

with the given shape parameters `n`

(number
of trials) and `p`

(probability of success).

##### §Known issues

Although this method should return an `Error`

on invalid parameters,
some (extreme) parameter combinations are known to return a `Binomial`

object which panics when sampled.
See #1378.

## Trait Implementations§

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

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

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

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

### impl Distribution<u64> for Binomial

### impl Copy for Binomial

### impl StructuralPartialEq for Binomial

## Auto Trait Implementations§

### impl Freeze for Binomial

### impl RefUnwindSafe for Binomial

### impl Send for Binomial

### impl Sync for Binomial

### impl Unpin for Binomial

### impl UnwindSafe for Binomial

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

`clone_to_uninit`

)