golang-petname icon indicating copy to clipboard operation
golang-petname copied to clipboard

Randomness behaviour with go 1.20

Open Bios-Marcel opened this issue 1 year ago • 0 comments

You've got this function calling rand.Seed for a non deterministic mode.

https://github.com/dustinkirkland/golang-petname/blob/e794b9370d4969374b205de6d84b7894d35c2812/petname.go#L45

However, since go 1.20, rand is automatically seeded, unless explicitly disabled:

// Prior to Go 1.20, the generator was seeded like Seed(1) at program startup.
// To force the old behavior, call Seed(1) at program startup.
// Alternately, set GODEBUG=randautoseed=0 in the environment
// before making any calls to functions in this package.

Maybe you want to factor this behaviour in, not sure. For me personally, I called rand.Seed manually beforehand and simply had no change in behaviour. But for people expecting something deterministic, this might be confusing. Additionaly, this library might want to stop using globalrand and instead allow specifying a source, as this makes it easier to use within projects that use randomness for other purposes.

Bios-Marcel avatar Aug 26 '23 11:08 Bios-Marcel