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

Numbers Dictionary does not respect seed #64

Open
obaqueiro-primetrust opened this issue Sep 8, 2022 · 1 comment
Open

Numbers Dictionary does not respect seed #64

obaqueiro-primetrust opened this issue Sep 8, 2022 · 1 comment

Comments

@obaqueiro-primetrust
Copy link

obaqueiro-primetrust commented Sep 8, 2022

The following code taken from the NumberDictionary example with an added seed: 0 will return different 3 digits when run at different times. This means that, although the generator is stable within the same run, the NumberDictionary.generate call introduces some kind of randomness that is not ruled by the seed:

const { uniqueNamesGenerator, NumberDictionary } = require('unique-names-generator');

const numberDictionary = NumberDictionary.generate({ min: 100, max: 999 });
const characterName = uniqueNamesGenerator({
dictionaries: [['Dangerous'], ['Snake'], numberDictionary],
  length: 3,
  separator: '',
  style: 'capital',
  seed: 0,
}); 

characterName

Copy and paste this code to a node interactive session, then exit the session, enter again and run it again. The characterName is the same except for the numbers.

@obaqueiro-primetrust
Copy link
Author

Seems the issue is in: https://github.com/andreasonny83/unique-names-generator/blob/main/src/dictionaries/numbers.ts#L21

The call to Math.random() does not allow a seed. I think the generate call should allow for a seed input.

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

No branches or pull requests

1 participant