I need to generate uniformly distributed random numbers for a Monte Carlo simulation. I read this thread Random double C++11 and followed the suggestions but, still, I am getting the same number whenever I run the program in Code Blocks. Here is my code:
#include <iostream>
#include <random>
int main(){
std::random_device rd; // use random_device to get a random seed
std::mt19937 mt(rd()); // mt19937 is a proper pseudo-random number generator
std::uniform_real_distribution<double> unif(0,1); // generate uniformly distributed random doubles in [0,1]
double x = unif(mt);
std::cout << x << std::endl;
}
Any suggestion why that happens?
Aucun commentaire:
Enregistrer un commentaire