I used the following code (copied somewhere from the web) and managed to generate some an array of random numbers.
std::default_random_engine generator;
std::uniform_real_distribution<double> distribution(0,1);
int N;
std::cout<< "Please enter the number of disks to be generated: ";
std::cin>> N;
// generates N pairs of coordinates
double** R;
R = new double* [N];
for (int i=0; i<N; i++) {
R[i] = new double [3];
for (int j=0; j<3; j++) {
R[i][j] = distribution(generator);
}
}
The problem is that the output is always the same, so I think it is not seeded properly. Then I found the following code from the web, but it didn't work on my computer (I always get runtime error)
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_real_distribution<> dis(1, 2);
for (int n = 0; n < 10; ++n) {
std::cout << dis(gen) << ' ';
}
std::cout << '\n';
What's wrong with the above code? How to seed my code so I can get different outputs everytime? Besides, for the first code, is the linear congruential algorithm being used? How to use 'better' algorithm like the Mersenne Twister (mt19937) ?
thanks