Randomiser seed
Closed this issue · 2 comments
Deleted user commented
I noticed that you explicitly do rand.Seed(time.Now().UnixNano())
in each call to randomFrom
.
Sometimes it is desirable to have a fixed seed for more reliable and predictable unit tests behaviour. Would it be possible to seed the randomiser only once, during package init and store the used seed? Additionally add a function that allows one to manually set the seed. Something like:
var seed int64
func Seed() int64 {
return seed
}
func SetSeed(v int64) {
seed = v
rand.Seed(v)
}
func init() {
SetSeed(time.Now().UnixNano())
}
Pallinder commented
Well, people can simply save the result they get initially and reuse it in their tests. I dont think it's necessary for us to have to do that.
Pallinder commented
Closing this for now, let's see if more people have an issue with this, if so, we'll re-open.