C++ random mt19937 Class
Example
Create random numbers with mt19937:
random_device rd;
mt19937 gen(rd());
cout << gen();
Definition and Usage
An mt19937 is a fast random number engine with good quality. It is the most common choice in C++.
In the example, a random_device gives the engine its starting value (seed), so you get different numbers each time the program runs.
The mt19937 class is defined in the <random> header file.
Note: The output is random, so it is different each time you run the program.
Syntax
mt19937 name(seed);
Parameter Values
| Parameter | Description |
|---|---|
| seed | Optional. The starting value. The same seed always gives the same numbers. |
Technical Details
| Returns: | Calling name() returns the next random number. |
|---|