3 ms·
My rand.Intn() was always returning the same value. Seem like you have to to seed it manually (once, in main() for example): rand.Seed( time.Now().UTC().UnixNan
by gizzlon 14y ago
My rand.Intn() was always returning the same value. Seem like you have to to seed it manually (once, in main() for example): rand.Seed( time.Now().UTC().UnixNano())
http://stackoverflow.com/questions/12321133/golang-random-number-generator-how-to-seed-properly http://stackoverflow.com/questions/12321133/golang-random-nu...
Edit: It's in the documentation, but you have to look for it.
"Seed uses the provided seed value to initialize the generator to a deterministic state. If Seed is not called, the generator behaves as if seeded by Seed(1)"