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

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

    Instead of straight time as measured in seconds from the C std lib time() function, could you instead use the processor's counter? Most processors have a free running tick count, for example in x86/x64 there's the Time Stamp Counter:

    The Time Stamp Counter is a 64-bit register present on all x86 processors since the Pentium. It counts the number of ticks since reset.

    (That page also has many ways to access this counter on different platforms -- gcc/ms visual c/etc)

    Keep in mind that the timestamp counter is not without flaws, it may not be synced across processors (you probably don't care for your application). And power saving features may clock up or down the processor (again you probably don't care).

提交回复
热议问题