I am running a Monte Carlo simulation where I generate 100,000 random paths. My problem is that I want to find a way to keep these same 100,000 random paths in loops of other variables. Essentially, I want my random number generator to reset each time I run my 100,000 iterations. Currently, I have code that looks something like this:
vector<double>Rand_Var(double time)
{
static mt19937 generator;
normal_distribution<>ND(0., 1.);
ND(generator);
double phi;
vector<double> rand(time + 1);
for (int i = 1; i <= time; i++)
{
phi = ND(generator);
rand[i] = phi;
}
return rand;
}
Then in int main(), for testing I have:
for (int l = 0; l < 5; l++)
{
for (int i = 0; i <= 1; i++)
{
vector<double>rand_val = Rand_Var(time_opt);
cout << rand_val[4] << endl;
}
}
I get the following output:
-0.214253
1.25608
-1.82735
0.919376
1.45366
-0.791957
0.530696
0.0751259
-0.559636
-0.709074
What I would like to get however is something like:
-0.214253
1.25608
-0.214253
1.25608
-0.214253
1.25608
-0.214253
1.25608
-0.214253
1.25608
Is this possible?
Aucun commentaire:
Enregistrer un commentaire