Is there an alternative to using time to seed a random number generation?

前端 未结 10 629
既然无缘
既然无缘 2020-11-27 06:30

I\'m trying to run several instances of a piece of code (2000 instances or so) concurrently in a computing cluster. The way it works is that I submit the jobs and the clust

10条回答
  •  离开以前
    2020-11-27 07:00

    unsigned seed;
    
    read(open("/dev/urandom", O_RDONLY), &seed, sizeof seed);
    srand(seed); // IRL, check for errors, close the fd, etc...
    

    I would also recommend a better random number generator.

提交回复
热议问题