Re:Go concurrency isn't parallelism: Real world lessons with...
by omni on Saturday February 07, 2015 @12:07PM
(#9014554)
It is indeed nanosecond precision. http://golang.org/pkg/time/#Time
Re:Go concurrency isn't parallelism: Real world lessons with...
by danbruc on Saturday February 07, 2015 @12:16PM
(#9014577)
The value is represented with nanosecond resolution, but that does not imply that Now() will return a different value every nanosecond.
Re:Go concurrency isn't parallelism: Real world lessons with...
by omni on Saturday February 07, 2015 @12:21PM
(#9014586)
You are of course technically correct. It seems the precision returned by Now may be platform-dependent. https://github.com/golang/go/blob/master/src/time/time.go#L7...
First, you are wasting cycles and with so little work to do before reseeding as in the code shown it probably matters quite a bit.
Second, some random number generators need some warm-up time producing lower quality random numbers at the beginning.
Third, if you are reseeding faster than your seed changes, you will repeatedly consume the same sequence of random numbers. I am not sure what the resolution of Now() is, but unless it is on the order of nanoseconds this will heavily affect the shown implementation.
If the resolution is one millisecond and it took 15 seconds to execute on a single thread, then the generated random values changed only every 74 iterations.