I've got a c++ program which is executed multiple times in parallel in a python script. The c++ program generates data utilizing rand(). The multiple processes are all generating identical data, presumably because they are all opened at the same time (I use srand(time(NULL)) as the seed.) How do I force the sub processes to diverge?
Asked
Active
Viewed 60 times
0
-
2There are probably lot of solutions to this. You could look at random generators in `
` and using `std::random_device` to initialize them. – Galik Dec 26 '19 at 13:37 -
Look at the 3rd answer in the link I just posted. – Shloim Dec 26 '19 at 13:39
-
Or delay the execution of each process – Storm Dec 26 '19 at 13:42
-
Or you could generate some random numbers in python and pass them as seeds to the C++-programs. – Lukas-T Dec 26 '19 at 13:59
-
@churill The random numbers are used in a monte-carlo simulation, so that would be too slow. I think I will define a randon_device at the beginning and invoke std::sample with mt_19937 as the generator. I think this is a fast way to choose from a vector over and over – basket Dec 26 '19 at 14:21