I am working on understanding the following code:
Question 1
To begin with I do not understand what this line does:
uint64_t timeSeed = chrono::high_resolution_clock::now().time_since_epoch().count();
Question 2
Is unif the variable that get created?
uniform_real_distribution<double> unif(0.0, 1.0);
and does a random seed get passed to it each time it is called?
currentRandomNumber = unif(rng);
I found this reference:
https://www.cplusplus.com/reference/random/uniform_real_distribution/
#include <iostream>
#include <random>
#include <chrono>
using namespace std;
int main()
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
{ // Initialize a random seed. This is not beginner code.
mt19937_64 rng; // A Mersenne Twister pseudo-random generator of 64-bit numbers with a state size of 19937 bits.
// initialize the random number generator with time-dependent seed
uint64_t timeSeed = chrono::high_resolution_clock::now().time_since_epoch().count();
seed_seq ss{uint32_t(timeSeed & 0xffffffff), uint32_t(timeSeed>>32)};
rng.seed(ss);
// initialize a uniform distribution between 0 and 1
uniform_real_distribution<double> unif(0.0, 1.0);
// ready to generate random numbers
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
int count = 0;
double currentRandomNumber = 0.0;
const int nSimulations = 1000;
for (int i = 0; i < nSimulations; i++)
{
currentRandomNumber = unif(rng);
cout << currentRandomNumber<<" ";
if(i % 15 == 0 && i != 0)cout<<endl;
}
return 0;
}