Class members

The result_type, min(), max() reset() and operator() members found in the C++11/14 standard library distributions are implemented.

The signature of the min(), max() and reset() functions is slightly altered, however, with the use of a dummy, defaulted template parameter. This allows the normal calling syntax to be preserved while deferring instantiation until the member function is explicitly referred to. The motivation for this signature is that, for composite distributions, these member functions need to call their counterparts from the user-supplied outer distributions, which have not necessarily been implemented. Deferring the instantiation of these member functions relieves therefore the user from the need to implement them in the provided outer distribution as long as the corresponding member functions are never used.

Member types

Type Description
result_type Type of the generated random variates (same as the first class template argument)

Member function operator()

template<class RngType>
RealType operator()(RngType& g);

Returns a random variate.

Parameter Description
RngType A type meeting the requirements of a C++11 uniform random number generator with the additional requirement that it should produce independent bits; this would in principle mean that its minimum value should be 0 and its maximum value a power of 2 less 1, but for the sake of practicality a minimum value of 1 and/or a maximum value equal to a power of 2 less 2 is tolerated (the bit correlations introduced by the relaxed requirement is usually weak enough to be ignored)

Why the additional requirement on RngType?

The issue at stake is C++11's mandated implementation of generate_canonical, which by trying to achieve too much genericity led to the infamous LWG issue 2524. There is very little hope that the issue can be fixed without a severe penalty on efficiency.

Putting aside backward compatibility issues, a reasonable solution to this problem is to require that independent bits be produced (in intent at least: pseudo random number generators obviously do not produce truly independent bits), allowing an efficient and robust implementation of generate_canonical() based on bit sequences obtained by simple concatenation or truncation of the generated numbers.

For this reason, the <etf> library internally uses generate_random_real() as a (nearly) drop-in replacement for generate_canonical(), and a related function, generate_random_integer(), both of which will assert at compile-time that the minimum value is 0 or 1 and that the maximum value is a power of 2 less 1 or less 2. Note that these requirements are satisfied by all default random number generators of the standard library, and are likely to be satisfied by the vast majority of commonly used generators.

Member function min() and max()

template<typename=void>
result_type min() const;
template<typename=void>
result_type max() const;

Returns the greatest lower bound and the least upper bound of the range of values potentially generated by operator().

Member function reset()

template<typename=void>
void reset();

Resets the distribution to ensure that the values generated by subsequent calls to operator() are independent from formerly generated values.

Since ETF distributions are stateless, this function only calls the reset() member of the user-supplied outer distribution (if there is one).

Member function operator=()

All distributions have implicitly-declared copy assignment operators, which may or may not be deleted depending on the types of associated functions and outer distributions.