A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/random/generate_canonical/ below:

function template

<random>

std::generate_canonical
template <class RealType, size_t bits, class URNG>  RealType generate_canonical (URNG& g);

Generate canonical numbers

Converts values generated by g into a floating-point value in the range [0,1) preserving the uniformity properties of sequences generated with g.

This may involve one or more calls to g.operator(), depending on the precision (template parameter bits) requested.



Template parameters
RealType
A floating-point type.
The function returns a value of this type.
bits
Maximum number of bits in the mantissa (the precision).
If this value is greater than the precision of the type, numeric_limits<RealType>::digits is used instead.
URNG
A uniform random number generator class.

Parameters
g
A uniform random number generator object, whose operator() is used to generate the values.

Return value The canonical equivalent to numbers generated by g.

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// generate_canonical
#include <iostream>
#include <chrono>
#include <limits>
#include <random>

int main ()
{
 // obtain a seed from the system clock:
  unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();

  std::default_random_engine generator (seed);
  double d = std::generate_canonical<double,std::numeric_limits<double>::digits>(generator);

  std::cout << "Canonical random value: " << d << std::endl;

  return 0;
}

Output:
Canonical random value: 0.349775


See also
uniform_real_distribution
Uniform real distribution (class template)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4