Because I'm using multi-threading, I need to define multiple random engines, one for each thread.
If I knew there are 4 threads, I would do:
std::default_random_engine generator1(1);
std::default_random_engine generator2(10000);
std::default_random_engine generator3(20000);
std::default_random_engine generator4(30000);
std::vector<std::default_random_engine> generators =
{generator1, generator2, generator3, generator4};
But how to do for an arbitrary number of threads? Sorry if this is obvious, I'm not familiar with C/C++.
EDIT
Hmm, maybe
std::vector<std::default_random_engine> generators(n);
for(i = 0; i < n; i++) {
std::default_random_engine generator(seeds[i]);
generators[i] = generator;
}
Aucun commentaire:
Enregistrer un commentaire