mercredi 20 mai 2020

c++ program not working in code block IDE

i have a simple C++ program to generate uniform distributed random numbers, the program is working properly in visual studio. but when i run it in the code block IDE i get repeated random number, how can i fix that pleas?

#include <random>
#include <functional>
#include <ctime>
#include<iostream>

using namespace std;
double Rand()
{
random_device seeder;
    const auto seed = seeder.entropy() ? seeder() : time(nullptr);
    mt19937 eng(static_cast<mt19937::result_type>(seed));
    uniform_real_distribution<double> dist(0, 1);
    auto gen = bind(dist, eng);
    return gen();
}
int main()
{
    srand((unsigned)time(0));

    for (unsigned int i = 0; i < 10; ++i)
    cout<<Rand()<<endl;

    return 0;
}



Aucun commentaire:

Enregistrer un commentaire