Consider an Euler integrator that solves a stochastic differential equation:
void euler(vector<double> &x0,
vector<double> &dxdt,
const double dt)
{
std::random_device rd;
std::mt19937 rng(rd());
std::normal_distribution<> dist(0, 1);
f(dxdt, t, dt)
for (int i=0; i<x0.size(); ++i)
x0[i] += dxdt[i] * dt + sqrt(dt) * 0.01 * dist(rng);
}
is this efficient to define the random generator for each time step integration? and probably there is a better option? another problem with this method is that when I try to fix the random seed
const unsigned int seed = 2;
std::mt19937 rng(seed);
for each time step, I get the same random numbers and this affects the answer.