---
name: "std::bernoulli_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::bernoulli_distribution/3cxx"
---

# std::bernoulli\_distribution(3cxx)

A Bernoulli random number distribution.

## NAME

std::bernoulli\_distribution - A Bernoulli random number distribution.

## SYNOPSIS

`#include <random>`

### Classes

struct **param\_type**\

### Public Types

**typedef** bool **result\_type**\

### Public Member Functions

**bernoulli\_distribution** ()\
 Constructs a Bernoulli distribution with likelihood 0.5.  **bernoulli\_distribution** (const **param\_type** &\_\_p)\
 **bernoulli\_distribution** (double \_\_p)\
 Constructs a Bernoulli distribution with likelihood `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 `p` parameter of the distribution.  **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.

### Friends

bool **operator==** (const **bernoulli\_distribution** &**\_\_d1**, const **bernoulli\_distribution** &**\_\_d2**)\
 Return true if two Bernoulli distributions have the same parameters.

## Detailed Description

A Bernoulli random number distribution.

Generates a sequence of true and false values with likelihood $p$ that true will come up and $(1 - p)$ that false will appear.

## Member Typedef Documentation

### typedef bool std::bernoulli\_distribution::result\_type

The type of the range of the distribution.

## Constructor & Destructor Documentation

### std::bernoulli\_distribution::bernoulli\_distribution ()` [inline]`

Constructs a Bernoulli distribution with likelihood 0.5.

### std::bernoulli\_distribution::bernoulli\_distribution (double \_\_p)` [inline]`, ` [explicit]`

Constructs a Bernoulli distribution with likelihood `p`.

**Parameters**

*\_\_p* \[IN\] The likelihood of a true result being returned. Must be in the interval $\[0, 1\]$.

## Member Function Documentation

### result\_type std::bernoulli\_distribution::max () const` [inline]`

Returns the least upper bound value of the distribution.

References **std::numeric\_limits\< \_Tp \>::max()**.

### result\_type std::bernoulli\_distribution::min () const` [inline]`

Returns the greatest lower bound value of the distribution.

References **std::numeric\_limits\< \_Tp \>::min()**.

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

Generating functions.

References **operator()()**.

Referenced by **operator()()**.

### double std::bernoulli\_distribution::p () const` [inline]`

Returns the `p` parameter of the distribution.

### param\_type std::bernoulli\_distribution::param () const` [inline]`

Returns the parameter set of the distribution.

Referenced by **std::operator\>\>()**.

### void std::bernoulli\_distribution::param (const param\_type & \_\_param)` [inline]`

Sets the parameter set of the distribution.

**Parameters**

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

### void std::bernoulli\_distribution::reset ()` [inline]`

Resets the distribution state. Does nothing for a Bernoulli distribution.

## Friends And Related Symbol Documentation

### bool operator== (const bernoulli\_distribution & \_\_d1, const bernoulli\_distribution & \_\_d2)` [friend]`

Return true if two Bernoulli distributions have the same parameters.

## Author

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