example1_basic_usage.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <random>
#include <ctime>

int main() {
    // Seed with current time
    std::mt19937 gen(static_cast<unsigned int>(std::time(0)));

    // Generate and print a few random numbers
    for (int i = 0; i < 5; ++i) {
        std::cout << "Random number: " << gen() << std::endl;
    }

    // Print the range of generated numbers
    std::cout << "Min value: " << gen.min() << std::endl;
    std::cout << "Max value: " << gen.max() << std::endl;

    return 0;
}
Back to std_mt19937