Skip to content

Conversation

@GramThanos
Copy link

@GramThanos GramThanos commented May 22, 2024

In some cases the ability to generate the same name based on a seed is needed, thus I added this functionality using a using a pseudorandom seedable number generator (using Antti Sykäri's algorithm from here)

The seeds can be used by passing a 2nd parameter:

const dockerNames = require('docker-names');
console.log(dockerNames.getRandomName(false, 'my-seed-here')); // Will always return the same name if the seed 'my-seed-here' is given
$ brave_ride

Also, support for custom random number generators was also added.

const dockerNames = require('docker-names');
console.log(dockerNames.getRandomName(false, {random : () => ((Math.random() + Math.random()) / 2)})); // Example of a custom random number generator
console.log(dockerNames.getRandomName(false, {random : () => 0.213456})); // Example of a not so random number generator (that will return determined_curie)

Or set it globally for all name generations

dockerNames.random_number_generator = {random : () => ((Math.random() + Math.random()) / 2)};
console.log(dockerNames.getRandomName());
console.log(dockerNames.getRandomName());

@GramThanos GramThanos changed the title Added name generation using seeds Added name generation using seeds or custom random number generator May 22, 2024
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 this pull request may close these issues.

1 participant