A distribution over random integers.

Synopsis

Declared in <absl/random/discrete_distribution.h>

template<typename IntType = int>
class discrete_distribution;

Description

A discrete distribution produces random integers i, where 0 <= i < n distributed according to the discrete probability function:

P(i|p0,...,pn‐1)=pi

This class is an implementation of discrete_distribution (see [rand.dist.samp.discrete]).

The algorithm used is Walker's Aliasing algorithm, described in Knuth, Vol 2. absl::discrete_distribution takes O(N) time to precompute the probabilities (where N is the number of possible outcomes in the distribution) at construction, and then takes O(1) time for each variate generation. Many other implementations also take O(N) time to construct an ordered sequence of partial sums, plus O(log N) time per variate to binary search.

Types

Name

Description

param_type

The parameter set of the distribution.

Type Aliases

Name

Description

result_type

The type of the values produced by the distribution.

Member Functions

Name

Description

discrete_distribution [constructor]

Constructors

max

Returns the largest value the distribution can produce.

min

Returns the smallest value the distribution can produce.

operator()

Function call operators

param

param overloads

probabilities

Returns the normalized probabilities of the outcomes.

reset

Resets the internal state of the distribution.

Friends

Name

Description

absl::operator!=

Compares two distributions for inequality.

absl::operator==

Compares two distributions for equality.

Created with MrDocs