Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
math/rand: convenience functions always use the same seed (1). at least use time.Now() #16486
Please answer these questions before submitting your issue. Thanks!
even most of the go programmers didn't notice this. there are about 60 tests in the standard library that use "math/rand", but only 2 call rand.Seed() with time.Now(). as such they do not really test random, but the same sequence again and again.
@adg every one of them, as someone who writes and/or reads and runs the test - without manually checking the random data - most probably will think the test runs with different data each time, when in fact it's the same data each time. yes, the data otherwise would be random, and as such only at random problems will be highlighted, but like this in tests that’s never the case.
this is especially true with out of bounds testing and shifting etc. especially with fuzzing.
@adg i'm saying the behavior is totally unexpected and COULD be harmful for tests with the strong implication that go programmers didn't notice this either. nothing more, nothing less.
i repeat myself: something that calls itself "random" should give back different data on each call - even beyond program begin/end. otherwise it's unexpected. this is true for every language i know of.
In your report you say:
But the docs say:
This also matches my expectation with standard library pseudo-random number generators in various languages. I don't think I've worked in an environment that seeds the PRNG for me.
We can't change this, anyway, because people may be depending on behavior. https://golang.org/doc/go1compat