Hacker News new | ask | show | jobs
by danbruc 4320 days 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.

1 comments

It is indeed nanosecond precision. http://golang.org/pkg/time/#Time
The value is represented with nanosecond resolution, but that does not imply that Now() will return a different value every nanosecond.
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...