Function utils::canonical

Function Documentation

inline auto utils::canonical(RngType &rng) -> double

Draw a uniform deviate in [0, 1)

This consumes exactly one engine output x, and returns x / 2^64, rounded to the nearest double. In the rare (probability 2^-54) case that the rounding produces exactly 1, it instead returns the largest double smaller than 1. This reproduces libstdc++’s std::generate_canonical as of GCC 14 (pre-P0952), and therefore also std::uniform_real_distribution<double>(0, 1). Newer versions of libstdc++ that implement P0952 instead draw again in that case, but are otherwise identical.

Parameters:

rng – The rng engine to draw from

Returns:

A uniform deviate in the range [0, 1)