2 ms·
It is in multiple ways. 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. Sec
by danbruc 12y ago
It is in multiple ways.
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.
- omni 12y agoIt is indeed nanosecond precision. http://golang.org/pkg/time/#Time http://golang.org/pkg/time/#Time
- danbruc 12y agoThe value is represented with nanosecond resolution, but that does not imply that Now() will return a different value every nanosecond.
- omni 12y agoYou 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#L777 https://github.com/golang/go/blob/master/src/time/time.go#L7...