---
name: "std::discrete_distribution"
section: "3"
platform: "linux"
package: "gcc"
version: "16.2.1+r23+gd564253eb6c8-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/std::discrete_distribution"
---

# std::discrete\_distribution(3)

A discrete\_distribution random number distribution.

## NAME

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

## SYNOPSIS

\#include \<random\>

### Classes

struct **param\_type**\

### Public Types

typedef \_IntType **result\_type**\

### Public Member Functions

template\<typename \_InputIterator\> **discrete\_distribution** (\_InputIterator \_\_wbegin, \_InputIterator \_\_wend)\
 **discrete\_distribution** (const **param\_type** &\_\_p)\
 **discrete\_distribution** (**initializer\_list**\< double \> \_\_wl)\
 template\<typename \_Func\> **discrete\_distribution** (size\_t \_\_nw, double \_\_xmin, double \_\_xmax, \_Func \_\_fw)\
 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)\
 **param\_type** **param** () const\
 Returns the parameter set of the distribution.  void **param** (const **param\_type** &\_\_param)\
 Sets the parameter set of the distribution.  **std::vector**\< double \> **probabilities** () const\
 Returns the probabilities of the distribution.  void **reset** ()\
 Resets the distribution state.

### Friends

template\<typename \_IntType1, typename \_CharT, typename \_Traits\> **std::basic\_ostream**\< \_CharT, \_Traits \> & **operator\<\<** (**std::basic\_ostream**\< \_CharT, \_Traits \> &\_\_os, const **std::discrete\_distribution**\< \_IntType1 \> &\_\_x)\
 Inserts a discrete\_distribution random number distribution \_\_x into the output stream \_\_os.  bool **operator==** (const discrete\_distribution &\_\_d1, const discrete\_distribution &\_\_d2)\
 Return true if two discrete distributions have the same parameters.  template\<typename \_IntType1, typename \_CharT, typename \_Traits\> **std::basic\_istream**\< \_CharT, \_Traits \> & **operator\>\>** (**std::basic\_istream**\< \_CharT, \_Traits \> &\_\_is, **std::discrete\_distribution**\< \_IntType1 \> &\_\_x)\
 Extracts a discrete\_distribution random number distribution \_\_x from the input stream \_\_is.

## Detailed Description

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

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

This distribution produces random numbers $ i, 0 d according to the probability mass function $ p(i \| p\_0, ..., p\_{n-1}) = p\_i $.

**Since**

C++11

## Member Typedef Documentation

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

The type of the range of the distribution.

## Member Function Documentation

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

Returns the least upper bound value of the distribution.

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

Returns the greatest lower bound value of the distribution.

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

Generating functions.

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

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

Returns the parameter set of the distribution.

### template\<typename \_IntType = int\> void std::discrete\_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\> std::vector\< double \> std::discrete\_distribution\< \_IntType \>::probabilities () const \[inline\]

Returns the probabilities of the distribution.

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

Resets the distribution state.

## 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::discrete\_distribution\< \_IntType1 \> & \_\_x) \[friend\]

Inserts a discrete\_distribution random number distribution \_\_x into the output stream \_\_os.

**Parameters**

*\_\_os* An output stream. \
 *\_\_x* A discrete\_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 discrete\_distribution\< \_IntType \> & \_\_d1, const discrete\_distribution\< \_IntType \> & \_\_d2) \[friend\]

Return true if two discrete distributions have the same parameters.

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

Extracts a discrete\_distribution random number distribution \_\_x from the input stream \_\_is.

**Parameters**

*\_\_is* An input stream. \
 *\_\_x* A discrete\_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.
