dimanche 9 août 2015

Generation of different sequence of random numbers that are normally distributed in c++

I was trying to generate random numbers that are normally distributed. I use the random header for c++11 and I got the random numbers but the same sequence is maintained whenever I execute the program. The question is how can I obtain different sequence anytime I execute the program? This is my code:

srand(time(NULL));
complex<double> finding[10];
complex<double> com_one(rand(), rand());
complex<double> com_two(rand(), rand());

mt19937 mt(1729);
normal_distribution<float>dist(0,1);
for(int i = 0; i<16; ++i){
cout << dist(mt)<<", ";
}
cout<<"\n\n"<<endl;

for(int i=0;i<10;i++){
    complex<double> com_three(rand(), rand());
    finding[i]= com_three;
}
for (int i =0; i<10;i++){
    cout <<"no "<<i<<" element of the finding array is: ";
    cout <<finding[i]<< endl;
}

cout << "The first complex number is" << endl;
cout << com_one.real() << "+" << com_one.imag()
      << "i" << endl;




Aucun commentaire:

Enregistrer un commentaire