I need to seed the random number generator in boost (which is loaded from an int) for a few processes, for a program that has to compile and work both in Windows and in Linux.
I used std:time(0), which worked, but since the processes are jobs which are run simultaneously, some of them would run at the same second, producing the same results.
So I need to seed it from milliseconds, or any other cross-platform random generator for that matter. I tried clock() but couldn’t quite make it convert from time_t to int.
Thanks.
If you are starting all the jobs from a single script.
Then you could pass an incremented number as an argument on the command line. Each Job then adds this value to the result of time() to generate its seed.
Note: I don’t see any requirement in the OP about security.
The original code is using time(NULL) and this will has a guessable seed.