function template
<random>
std::generate_canonicaltemplate <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.
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;
}
Canonical random value: 0.349775
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