<random> functions

Visual Studio 2015
 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

The latest version of this topic can be found at <random> functions.

generate_canonical](#generate_canonical)|

Returns a floating-point value from a random sequence.

System_CAPS_ICON_note.jpg Note

The ISO C++ Standard states that this function should return values in the range [ 0, 1). Visual Studio is not yet compliant with this constraint. As a workaround to generate values in this range, use uniform_real_distribution.

template <class RealType, size_t Bits, class Generator>  
RealType generate_canonical(Generator& Gen);

Parameters

RealType
The floating point integral type. For possible types, see <random>.

Bits
The random number generator.

Gen
The random number generator.

Remarks

The template function calls operator() of Gen repeatedly and packs the returned values into a floating-point value x of type RealType until it has gathered the specified number of mantissa bits in x. The specified number is the smaller of Bits (which must be nonzero) and the full number of mantissa bits in RealType. The first call supplies the lowest-order bits. The function returns x.

<random>

Show: