Skip to content
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

Petname generation is not "random" unless rand.Seed is set #10

Open
jdhayford opened this issue May 4, 2019 · 3 comments
Open

Petname generation is not "random" unless rand.Seed is set #10

jdhayford opened this issue May 4, 2019 · 3 comments

Comments

@jdhayford
Copy link

This is fairly obvious after taking a peek at the source and seeing the use of rand.Intn. That said I think it would be a good idea to add a note in the Readme about this and recommend setting the seed before generating any petnames using the library. If this is the case and I'm not missing something I'd be happy to spin up a PR.

Thanks for the library!

@jdhayford jdhayford changed the title Petnames are not random unless rand.Seed is set Petname generation is not "random" unless rand.Seed is set May 4, 2019
@dustinkirkland
Copy link
Owner

dustinkirkland commented Jun 13, 2019 via email

@romainverduci
Copy link

Hi !
I'm using the lib for test automation and I'd like to have a "non deterministic" mode so when the tests run multiple times they don't produce the same test data.
@dustinkirkland I'm happy to submit a PR for this mode but is that something you would like the lib to support ?

Cheers :)

@dustinkirkland
Copy link
Owner

dustinkirkland commented Jun 27, 2019 via email

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
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants