std::generate_canonical
Min standard notice:
Header: <random>
Generates a random floating point number in range [0,1).
# Declarations
template< class RealType, std::size_t Bits, class Generator >
RealType generate_canonical( Generator& g );
(since C++11)
# Parameters
g: generator to use to acquire entropy
# Return value
Floating point value in range [0,1).
# Notes
Some existing implementations have a bug where they may occasionally return 1.0 if RealType is float GCC #63176 LLVM #18767 MSVC STL #1074. This is LWG issue 2524.
# Example
#include <iostream>
#include <random>
int main()
{
std::random_device rd;
std::mt19937 gen(rd());
for (int n = 0; n < 10; ++n)
std::cout << std::generate_canonical<double, 10>(gen) << ' ';
std::cout << '\n';
}