generate_canonical Function template in C++
generate_canonical()
Syntax:
template ( class RealType, size_t bits, class URNG ) RealType generate_canonical (URNG& g);
Template parameters:
- RealType: The function returns a value of floating point type.
- bits: Maximum number of bits in the mantissa.
- URNG: A uniform random number generator class.
Parameters:
g
Return value:
Program:
// C++ program to illustrate generate_canonical() // function. #include <bits/stdc++.h> using namespace std; int main() { // Obtain a root from the system clock: unsigned root = chrono::system_clock::now().time_since_epoch().count(); // Random number engine class // that generates pseudo-random numbers default_random_engine generator(root); double can_val = generate_canonical< double , numeric_limits< double >::digits>(generator); // Print the random canonical value // It will display different value everytime cout << "Random canonical value: " << can_val; return 0; } |
Output:
Random canonical value: 0.0281975
Reference:
http://www.cplusplus.com/reference/random/generate_canonical/