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

前端 未结 10 631
既然无缘
既然无缘 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:07

    Assuming you're on a reasonably POSIX-ish system, you should have clock_gettime. This will give the current time in nanoseconds, which means for all practical purposes it's impossible to ever get the same value twice. (In theory bad implementations could have much lower resolution, e.g. just multiplying milliseconds by 1 million, but even half-decent systems like Linux give real nanosecond results.)

提交回复
热议问题