Seed random from milliseconds on Windows and Linux

I need to plant a random number generator in boost (which is loaded from int) for several processes, for a program that needs to compile and work on both Windows and Linux.

I used std:time(0)one that worked, but since processes are tasks that run simultaneously, some of them will run in one second, producing the same results.

So I need to sow it in milliseconds or any other cross-platform random generator. I tried clock(), but could not convert it from time_tto int.

Thank.

+3
source share
2 answers

script.

. time() .

. OP .
(NULL), .

int main(int argc,char* argv[])
{
    srand(time(NULL) + boost::lexical_cast<int>(argv[1]));

    // STUFF
}
0

, . Linux /dev/urandom . Windows - UuidCreate.

+3

Source: https://habr.com/ru/post/1763303/


All Articles