Przejdź do głównej zawartości

C++ named requirements: UniformRandomBitGenerator (od C++11)

A uniform random bit generator is a function object returning unsigned integer values such that each value in the range of possible results has (ideally) equal probability.

Uniform random bit generators are not intended to be used as random number generators: they are used as the source of random bits (generated in bulk, for efficiency). Any uniform random bit generator may be plugged into any random number distribution in order to obtain a random number (formally, a random variate).

Requirements

The type G satisfies UniformRandomBitGenerator if given

  • T, the type named by G::result_type
  • g, a value of type G The following expressions must be valid and have their specified effects:
ExpressionReturn typeRequirements
G::result_typeTT is an unsigned integer type
G::min()TReturns the smallest value that G's operator() may return. The value is strictly less than G::max(). The function must be constexpr.
G::max()TReturns the largest value that G's operator() may return. The value is strictly greater than G::min(). The function must be constexpr.
g()TReturns a value in the closed interval [G::min(), G::max()]. Has amortized constant complexity.

Notes

All RandomNumberEngines satisfy this requirement.

Standard library

The following standard library facilities expect a UniformRandomBitGenerator type.

pubrandom_shuffle (do C++17)
shuffle(C++11)
randomly re-orders elements in a range
pubgenerate_canonical(C++11)evenly distributes real values of given precision across [0, 1)
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
puball other random number distributions

The following standard library facilities satisfy UniformRandomBitGenerator without additionally satisfying RandomNumberEngine:

pubrandom_device(C++11)non-deterministic random number generator using hardware entropy source

C++ named requirements: UniformRandomBitGenerator (od C++11)

A uniform random bit generator is a function object returning unsigned integer values such that each value in the range of possible results has (ideally) equal probability.

Uniform random bit generators are not intended to be used as random number generators: they are used as the source of random bits (generated in bulk, for efficiency). Any uniform random bit generator may be plugged into any random number distribution in order to obtain a random number (formally, a random variate).

Requirements

The type G satisfies UniformRandomBitGenerator if given

  • T, the type named by G::result_type
  • g, a value of type G The following expressions must be valid and have their specified effects:
ExpressionReturn typeRequirements
G::result_typeTT is an unsigned integer type
G::min()TReturns the smallest value that G's operator() may return. The value is strictly less than G::max(). The function must be constexpr.
G::max()TReturns the largest value that G's operator() may return. The value is strictly greater than G::min(). The function must be constexpr.
g()TReturns a value in the closed interval [G::min(), G::max()]. Has amortized constant complexity.

Notes

All RandomNumberEngines satisfy this requirement.

Standard library

The following standard library facilities expect a UniformRandomBitGenerator type.

pubrandom_shuffle (do C++17)
shuffle(C++11)
randomly re-orders elements in a range
pubgenerate_canonical(C++11)evenly distributes real values of given precision across [0, 1)
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
puball other random number distributions

The following standard library facilities satisfy UniformRandomBitGenerator without additionally satisfying RandomNumberEngine:

pubrandom_device(C++11)non-deterministic random number generator using hardware entropy source