---
name: "std::binomial_distribution"
section: "3cxx"
platform: "linux"
package: "libstdc++-12-doc"
version: "12.4.0-5"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/std::binomial_distribution/3cxx"
---

# std::binomial\_distribution(3cxx)

A discrete binomial random number distribution.

## NAME

std::binomial\_distribution\< \_IntType \> - A discrete binomial random number distribution.

## SYNOPSIS

`#include <random>`

### Classes

struct **param\_type**\

### Public Types

**typedef** \_IntType **result\_type**\

### Public Member Functions

**binomial\_distribution** (\_IntType \_\_t, double \_\_p=0.5)\
 **binomial\_distribution** (const **param\_type** &\_\_p)\
 template\<**typename** **\_ForwardIterator** , **typename** **\_UniformRandomNumberGenerator** \> **void** **\_\_generate** (**\_ForwardIterator** \_\_f, **\_ForwardIterator** \_\_t, **\_UniformRandomNumberGenerator** &**\_\_urng**)\
 template\<**typename** **\_ForwardIterator** , **typename** **\_UniformRandomNumberGenerator** \> **void** **\_\_generate** (**\_ForwardIterator** \_\_f, **\_ForwardIterator** \_\_t, **\_UniformRandomNumberGenerator** &**\_\_urng**, const **param\_type** &\_\_p)\
 template\<**typename** **\_UniformRandomNumberGenerator** \> **void** **\_\_generate** (**result\_type** \*\_\_f, **result\_type** \*\_\_t, **\_UniformRandomNumberGenerator** &**\_\_urng**, const **param\_type** &\_\_p)\
 **result\_type** **max** () const\
 Returns the least upper bound value of the distribution.  **result\_type** **min** () const\
 Returns the greatest lower bound value of the distribution.  template\<**typename** **\_UniformRandomNumberGenerator** \> **result\_type** **operator()** (**\_UniformRandomNumberGenerator** &**\_\_urng**)\
 Generating functions.  template\<**typename** **\_UniformRandomNumberGenerator** \> **result\_type** **operator()** (**\_UniformRandomNumberGenerator** &**\_\_urng**, const **param\_type** &\_\_p)\
 double **p** () const\
 Returns the distribution `p` parameter.  **param\_type** **param** () const\
 Returns the parameter set of the distribution.  **void** **param** (const **param\_type** &**\_\_param**)\
 Sets the parameter set of the distribution.  **void** **reset** ()\
 Resets the distribution state.  \_IntType **t** () const\
 Returns the distribution `t` parameter.

### Friends

template\<**typename** **\_IntType1** , **typename** \_CharT , **typename** \_Traits \> **std::basic\_ostream**\< \_CharT, \_Traits \> & **operator\<\<** (**std::basic\_ostream**\< \_CharT, \_Traits \> &**\_\_os**, const **std::binomial\_distribution**\< **\_IntType1** \> &\_\_x)\
 Inserts a binomial\_distribution random number distribution `__x` into the output stream `__os`.  bool **operator==** (const **binomial\_distribution** &**\_\_d1**, const **binomial\_distribution** &**\_\_d2**)\
 Return true if two binomial distributions have the same parameters and the sequences that would be generated are equal.  template\<**typename** **\_IntType1** , **typename** \_CharT , **typename** \_Traits \> **std::basic\_istream**\< \_CharT, \_Traits \> & **operator\>\>** (**std::basic\_istream**\< \_CharT, \_Traits \> &**\_\_is**, **std::binomial\_distribution**\< **\_IntType1** \> &\_\_x)\
 Extracts a binomial\_distribution random number distribution `__x` from the input stream `__is`.

## Detailed Description

### template\<typename \_IntType = int\>

class std::binomial\_distribution\< \_IntType \>"A discrete binomial random number distribution.

The formula for the binomial probability density function is $p(i\|t,p) = } p^i (1 - p)^{t - i}$ where $t$ and $p$ are the parameters of the distribution.

## Member Typedef Documentation

### template\<typename \_IntType = int\> typedef \_IntType std::binomial\_distribution\< \_IntType \>::result\_type

The type of the range of the distribution.

## Member Function Documentation

### template\<typename \_IntType = int\> result\_type std::binomial\_distribution\< \_IntType \>::max () const` [inline]`

Returns the least upper bound value of the distribution.

### template\<typename \_IntType = int\> result\_type std::binomial\_distribution\< \_IntType \>::min () const` [inline]`

Returns the greatest lower bound value of the distribution.

### template\<typename \_IntType = int\> template\<typename \_UniformRandomNumberGenerator \> result\_type std::binomial\_distribution\< \_IntType \>::operator() (\_UniformRandomNumberGenerator & \_\_urng)` [inline]`

Generating functions.

References **std::binomial\_distribution\< \_IntType \>::operator()()**.

Referenced by **std::binomial\_distribution\< \_IntType \>::operator()()**.

### template\<typename \_IntType \> template\<typename \_UniformRandomNumberGenerator \> binomial\_distribution\< \_IntType \>::result\_type std::binomial\_distribution\< \_IntType \>::operator() (\_UniformRandomNumberGenerator & \_\_urng, const param\_type & \_\_param)

A rejection algorithm when t \* p \>= 8 and a simple waiting time method - the second in the referenced book - otherwise. NB: The former is available only if \_GLIBCXX\_USE\_C99\_MATH\_TR1 is defined.

Reference: Devroye, L. Non-Uniform Random Variates Generation. Springer-Verlag, New York, 1986, Ch. X, Sect. 4 (+ Errata!).

References **std::abs()**, **std::numeric\_limits\< \_Tp \>::epsilon()**, **std::log()**, and **std::numeric\_limits\< \_Tp \>::max()**.

### template\<typename \_IntType = int\> double std::binomial\_distribution\< \_IntType \>::p () const` [inline]`

Returns the distribution `p` parameter.

### template\<typename \_IntType = int\> param\_type std::binomial\_distribution\< \_IntType \>::param () const` [inline]`

Returns the parameter set of the distribution.

### template\<typename \_IntType = int\> void std::binomial\_distribution\< \_IntType \>::param (const param\_type & \_\_param)` [inline]`

Sets the parameter set of the distribution.

**Parameters**

*\_\_param* The new parameter set of the distribution.

### template\<typename \_IntType = int\> void std::binomial\_distribution\< \_IntType \>::reset ()` [inline]`

Resets the distribution state.

References **std::normal\_distribution\< \_RealType \>::reset()**.

### template\<typename \_IntType = int\> \_IntType std::binomial\_distribution\< \_IntType \>::t () const` [inline]`

Returns the distribution `t` parameter.

## Friends And Related Symbol Documentation

### template\<typename \_IntType = int\> template\<typename \_IntType1 , typename \_CharT , typename \_Traits \> std::basic\_ostream\< \_CharT, \_Traits \> & operator\<\< (std::basic\_ostream\< \_CharT, \_Traits \> & \_\_os, const std::binomial\_distribution\< \_IntType1 \> & \_\_x)` [friend]`

Inserts a binomial\_distribution random number distribution `__x` into the output stream `__os`.

**Parameters**

*\_\_os* An output stream. \
 *\_\_x* A binomial\_distribution random number distribution.

**Returns**

The output stream with the state of `__x` inserted or in an error state.

### template\<typename \_IntType = int\> bool operator== (const binomial\_distribution\< \_IntType \> & \_\_d1, const binomial\_distribution\< \_IntType \> & \_\_d2)` [friend]`

Return true if two binomial distributions have the same parameters and the sequences that would be generated are equal.

### template\<typename \_IntType = int\> template\<typename \_IntType1 , typename \_CharT , typename \_Traits \> std::basic\_istream\< \_CharT, \_Traits \> & operator\>\> (std::basic\_istream\< \_CharT, \_Traits \> & \_\_is, std::binomial\_distribution\< \_IntType1 \> & \_\_x)` [friend]`

Extracts a binomial\_distribution random number distribution `__x` from the input stream `__is`.

**Parameters**

*\_\_is* An input stream. \
 *\_\_x* A binomial\_distribution random number generator engine.

**Returns**

The input stream with `__x` extracted or in an error state.

## Author

Generated automatically by Doxygen for libstdc++ from the source code.
