[Solved] How to generate pseudorandom no. easily? [closed]


Here’s a simple example that generates 10 evenly distributed random numbers in the range -42 to 42 :

#include <iostream>
#include <functional>
#include <random>
int main()
{
    std::random_device seed_device;
    std::mt19937 engine(seed_device());
    std::uniform_int_distribution<int> distribution(-42, 42);
    auto rnd = std::bind(distribution, std::ref(engine));
    for (int i = 0; i < 10; ++i) {
        std::cout << "random number: " << rnd() << "\n";
    }
    return 0;
}

See also:

http://en.cppreference.com/w/cpp/header/random

3

solved How to generate pseudorandom no. easily? [closed]