Skip to main content

C++ named requirements:
RandomNumberDistribution (since C++11)

A RandomNumberDistribution is a function object returning random numbers according to a probability density function p(x) or a discrete probability distribution P(xi).

Requirements

The type D satisfies RandomNumberDistribution if

Given

  • T, the type named by D::result_type
  • P, the type named by D::param_type, which
    • satisfies CopyConstructible
    • satisfies CopyAssignable
    • satisfies EqualityComparable
    • has a constructor taking identical arguments as each of the constructors of D that take arguments corresponding to the distribution parameters.
    • has a member function with the identical name, type, and semantics, as every member function of D that returns a parameter of the distribution
    • declares a member typedef using distribution_type = D;
  • d, a value of type D
  • x and y, (possibly const) values of type D
  • p, a (possibly const) value of type P
  • g, g1, g2, lvalues of a type satisfying UniformRandomBitGenerator
  • os, lvalue of a specialization of std::basic_ostream
  • is, lvalue of a specialization of std::basic_istream

The following expressions must be valid and have their specified effects

ExpressionTypeNotesComplexity
D::result_typeTAn arithmetic typecompile-time
D::param_typePcompile-time
D()creates a distribution indistinguishable from any other default-constructed Dconstant
D(p)creates a distribution indistinguishable from D constructed directly from the values used to construct pSame as p's construction
d.reset()voidResets the internal state of the distribution. The next call to operator() on d will not depend on values produced by any engine prior to reset().constant
x.param()PReturns p such that D(p).param() == pNo worse than D(p)
d.param(p)voidPostcondition: d.param() == pNo worse than D(p)
d(g)TThe sequence of numbers returned by successive invocations of this call with the same g are randomly distributed according to the distribution parametrized by d.param()Amortized constant number of invocations of g
d(g,p)TThe sequence of numbers returned by successive invocations of this call with the same g are randomly distributed according to the distribution parametrized by pAmortized constant number of invocations of g
x.min()Tthe greatest lower bound on the values potentially returned by x’s operator(), as determined by the current values of x’s parametersconstant
x.max()Tthe least upper bound on the values potentially returned by x’s operator(), as determined by the current values of x’s parametersconstant
x == yboolEstablishes an equivalence relation. Returns true if x.param() == y.param() and future infinite sequences of values that would be generated by repeated invocations of x(g1) and y(g2) would be equal as long as g1 == g2.constant
x != ybool!(x == y)constant
os << xReference to the type of osWrites a textual representation of the distribution parameters and internal state to os. The formatting flags and fill character of os are unchanged.
is >> dReference to the type of isRestores the distribution parameters and internal state with data read from is. The formatting flags of is are unchanged. The data must have been written using a stream with the same locale, CharT and Traits stream template parameters, otherwise the behavior is undefined. If bad input is encountered, is.setstate(std::ios::failbit) is called, which may throw std::ios_base::failure. d is unchanged in that case.

Notes

The parameters of a distribution object may be changed either permanently, by using d.param(p) or just for the duration of a single operator() call, by using d(g,p).

Calls to const member functions of the distribution and os << d do not affect the sequence of numbers produced by repeated d(g).

Standard library

The following standard library components satisfy RandomNumberDistribution

pubuniform_int_distribution(C++11)produces integer values evenly distributed across a range
pubuniform_real_distribution(C++11)produces real values evenly distributed across a range
pubbernoulli_distribution(C++11)produces bool values on a Bernoulli distribution
pubbinomial_distribution(C++11)produces integer values on a binomial distribution
pubnegative_binomial_distribution(C++11)produces integer values on a negative binomial distribution
pubgeometric_distribution(C++11)produces integer values on a geometric distribution
pubpoisson_distribution(C++11)produces integer values on a poisson distribution
pubexponential_distribution(C++11)produces real values on an exponential distribution
pubgamma_distribution(C++11)produces real values on an gamma distribution
pubweibull_distribution(C++11)produces real values on a Weibull distribution
pubextreme_value_distribution(C++11)produces real values on an extreme value distribution
pubnormal_distribution(C++11)produces real values on a standard normal (Gaussian) distribution
publognormal_distribution(C++11)produces real values on a lognormal distribution
pubchi_squared_distribution(C++11)produces real values on a chi-squared distribution
pubcauchy_distribution(C++11)produces real values on a Cauchy distribution
pubfisher_f_distribution(C++11)produces real values on a Fisher'sF-distribution
pubstudent_t_distribution(C++11)produces real values on a Student's t-distribution
pubdiscrete_distribution(C++11)produces random integers on a discrete distribution
pubpiecewise_constant_distribution(C++11)produces real values distributed on constant subintervals
pubpiecewise_linear_distribution(C++11)produces real values distributed on defined subintervals

C++ named requirements:
RandomNumberDistribution (since C++11)

A RandomNumberDistribution is a function object returning random numbers according to a probability density function p(x) or a discrete probability distribution P(xi).

Requirements

The type D satisfies RandomNumberDistribution if

Given

  • T, the type named by D::result_type
  • P, the type named by D::param_type, which
    • satisfies CopyConstructible
    • satisfies CopyAssignable
    • satisfies EqualityComparable
    • has a constructor taking identical arguments as each of the constructors of D that take arguments corresponding to the distribution parameters.
    • has a member function with the identical name, type, and semantics, as every member function of D that returns a parameter of the distribution
    • declares a member typedef using distribution_type = D;
  • d, a value of type D
  • x and y, (possibly const) values of type D
  • p, a (possibly const) value of type P
  • g, g1, g2, lvalues of a type satisfying UniformRandomBitGenerator
  • os, lvalue of a specialization of std::basic_ostream
  • is, lvalue of a specialization of std::basic_istream

The following expressions must be valid and have their specified effects

ExpressionTypeNotesComplexity
D::result_typeTAn arithmetic typecompile-time
D::param_typePcompile-time
D()creates a distribution indistinguishable from any other default-constructed Dconstant
D(p)creates a distribution indistinguishable from D constructed directly from the values used to construct pSame as p's construction
d.reset()voidResets the internal state of the distribution. The next call to operator() on d will not depend on values produced by any engine prior to reset().constant
x.param()PReturns p such that D(p).param() == pNo worse than D(p)
d.param(p)voidPostcondition: d.param() == pNo worse than D(p)
d(g)TThe sequence of numbers returned by successive invocations of this call with the same g are randomly distributed according to the distribution parametrized by d.param()Amortized constant number of invocations of g
d(g,p)TThe sequence of numbers returned by successive invocations of this call with the same g are randomly distributed according to the distribution parametrized by pAmortized constant number of invocations of g
x.min()Tthe greatest lower bound on the values potentially returned by x’s operator(), as determined by the current values of x’s parametersconstant
x.max()Tthe least upper bound on the values potentially returned by x’s operator(), as determined by the current values of x’s parametersconstant
x == yboolEstablishes an equivalence relation. Returns true if x.param() == y.param() and future infinite sequences of values that would be generated by repeated invocations of x(g1) and y(g2) would be equal as long as g1 == g2.constant
x != ybool!(x == y)constant
os << xReference to the type of osWrites a textual representation of the distribution parameters and internal state to os. The formatting flags and fill character of os are unchanged.
is >> dReference to the type of isRestores the distribution parameters and internal state with data read from is. The formatting flags of is are unchanged. The data must have been written using a stream with the same locale, CharT and Traits stream template parameters, otherwise the behavior is undefined. If bad input is encountered, is.setstate(std::ios::failbit) is called, which may throw std::ios_base::failure. d is unchanged in that case.

Notes

The parameters of a distribution object may be changed either permanently, by using d.param(p) or just for the duration of a single operator() call, by using d(g,p).

Calls to const member functions of the distribution and os << d do not affect the sequence of numbers produced by repeated d(g).

Standard library

The following standard library components satisfy RandomNumberDistribution

pubuniform_int_distribution(C++11)produces integer values evenly distributed across a range
pubuniform_real_distribution(C++11)produces real values evenly distributed across a range
pubbernoulli_distribution(C++11)produces bool values on a Bernoulli distribution
pubbinomial_distribution(C++11)produces integer values on a binomial distribution
pubnegative_binomial_distribution(C++11)produces integer values on a negative binomial distribution
pubgeometric_distribution(C++11)produces integer values on a geometric distribution
pubpoisson_distribution(C++11)produces integer values on a poisson distribution
pubexponential_distribution(C++11)produces real values on an exponential distribution
pubgamma_distribution(C++11)produces real values on an gamma distribution
pubweibull_distribution(C++11)produces real values on a Weibull distribution
pubextreme_value_distribution(C++11)produces real values on an extreme value distribution
pubnormal_distribution(C++11)produces real values on a standard normal (Gaussian) distribution
publognormal_distribution(C++11)produces real values on a lognormal distribution
pubchi_squared_distribution(C++11)produces real values on a chi-squared distribution
pubcauchy_distribution(C++11)produces real values on a Cauchy distribution
pubfisher_f_distribution(C++11)produces real values on a Fisher'sF-distribution
pubstudent_t_distribution(C++11)produces real values on a Student's t-distribution
pubdiscrete_distribution(C++11)produces random integers on a discrete distribution
pubpiecewise_constant_distribution(C++11)produces real values distributed on constant subintervals
pubpiecewise_linear_distribution(C++11)produces real values distributed on defined subintervals