2

I do not why, but in Windows (with MinGW) this code generates for 3/4 time the same pseudo-random number. I think that is because I set badly the seed, but I can not correct it.

Thank you for your help.

Here there is the code:

#include <iostream>
#include <random>
#include <chrono>

int main()
{   

double Nprove = 50.0;
double p = 0.2;  
const int Ncampioni = 100; // number of samples

int cappa = 0;
double sample[Ncampioni];

unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();

std::mt19937 gen(seed);
std::binomial_distribution<> d(Nprove, 0.9);

for(cappa = 0; cappa < Ncampioni; cappa = cappa +1){ 
    sample[cappa] = d(gen);
    std::cout << cappa << "," << sample[cappa] << std::endl;
    }

}
Zara
  • 21
  • 2
  • This doesn't compile for me. – Rob Jul 13 '18 at 12:20
  • @Rob Try it here: https://ideone.com/W3gVbV – VLL Jul 13 '18 at 12:24
  • Possible duplicate of [Why do I get the same sequence for every run with std::random\_device with mingw gcc4.8.1?](https://stackoverflow.com/questions/18880654/why-do-i-get-the-same-sequence-for-every-run-with-stdrandom-device-with-mingw) – orhtej2 Jul 13 '18 at 12:26
  • Sorry, I did not explain my problem well. Now I have midified the text. – Zara Jul 16 '18 at 07:27

0 Answers0