jeudi 16 février 2023

Where is it better to store random_device/mt19937?

I have a function which makes use of randomness

void fun() {
    random_device rd;
    mt19937 gen(rd());
    uniform_real_distribution<double> dis(0.0, 1.0);
    // ...
}

And, as I suspect, I'll get poor random if it's call repeatedly and both rd and gen are created each time. Is it better to make these variables global/private fields of a class so they are not redeclared multiple times?




Aucun commentaire:

Enregistrer un commentaire