lundi 29 février 2016

C++ random class repeat values when run [duplicate]

How do I change this so it gives a different set of values each time it is run?

#include <random>
#include <iostream>

using namespace std;

int main()
{
    random_device rd;
    mt19937 gen(rd()); 

    for(int i=0; i<10; i++)
    {
        std::cout << "Random Num " << i << " = " << gen() << "\n";
    }
}

Right now it gives the same result each time:

Random Num 0 = 2412496532
Random Num 1 = 3119216746
Random Num 2 = 1495923606
Random Num 3 = 3931352601
Random Num 4 = 26313293
Random Num 5 = 2552602825
Random Num 6 = 3745457912
Random Num 7 = 2213446826
Random Num 8 = 4119067789
Random Num 9 = 4188234190




Aucun commentaire:

Enregistrer un commentaire