mercredi 8 novembre 2017

C++

I am trying to learn how to use the c++11 library by generating a pair of distinct random reals in the range of 0.0 to 2.0. However when I run my code, I get the same numbers despite the fact that I am using different seeds and generators. Can someone help me understand the problem?

void randPairs(){
    random_device rd0;
    random_device rd1;
    mt19937 gen0(rd0());
    mt19937 gen1(rd1());
    uniform_real_distribution<> dis0(0,2.0);
    uniform_real_distribution<> dis1(0,2.0);
    for(int i = 0; i < 10; i++){
        cout<<dis0(gen0)<<", "<<dis1(gen1)<<endl;
    }

the output is:

1.32312, 1.32312
1.0573, 1.0573
1.57699, 1.57699
0.148201, 0.148201
0.6597, 0.6597

I also get the same results every time I run it, not sure why that is either.




Aucun commentaire:

Enregistrer un commentaire