-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Randomness behaviour with go 1.20 #15
Comments
Bios-Marcel
added a commit
to Bios-Marcel/golang-petname
that referenced
this issue
Aug 26, 2023
Pre go1.20, rand.Seed needed to be called for randomness. Meaning, that math/rand delivered deterministic values by default. This was changed however. To restore the old behaviour, we need to manually seed our random generator with a constant. Additionally, this introduce a local instance of rand.Rand, in order to prevent unexpected behaviour with other code that relies on the global math/rand package. Fixes dustinkirkland#10 (The readme and docs explain this, therefore I consider this solved, as it is by design and not a bug) Fixes dustinkirkland#15
Bios-Marcel
added a commit
to Bios-Marcel/golang-petname
that referenced
this issue
Aug 26, 2023
Pre go1.20, rand.Seed needed to be called for randomness. Meaning, that math/rand delivered deterministic values by default. This was changed however. To restore the old behaviour, we need to manually seed our random generator with a constant. Additionally, this introduce a local instance of rand.Rand, in order to prevent unexpected behaviour with other code that relies on the global math/rand package. Fixes dustinkirkland#10 (The readme and docs explain this, therefore I consider this solved, as it is by design and not a bug) Fixes dustinkirkland#15
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You've got this function calling rand.Seed for a non deterministic mode.
golang-petname/petname.go
Line 45 in e794b93
However, since go 1.20, rand is automatically seeded, unless explicitly disabled:
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.
The text was updated successfully, but these errors were encountered: