C++ random uniform_real_distribution Class
Example
Get a random decimal number between 0.0 and 1.0:
random_device rd;
mt19937 gen(rd());
uniform_real_distribution<double> dist(0.0, 1.0);
cout << dist(gen);
Definition and Usage
A uniform_real_distribution gives random decimal numbers from the minimum value, up to (but not including) the maximum value. Every number has the same chance.
The uniform_real_distribution class is defined in the <random> header file.
Note: The output is random, so it is different each time you run the program.
Syntax
uniform_real_distribution<type> name(min, max);
Parameter Values
| Parameter | Description |
|---|---|
| type | Optional. A decimal type, like double (default) or float. |
| min | Required. The smallest possible number. |
| max | Required. The number that all results are smaller than. |
Technical Details
| Returns: | Calling name(engine) returns a random decimal number. |
|---|