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

Added name generation using seeds or custom random number generator #7

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,26 @@ $ backstabbing_roentgen5
```
`*` This uses Math.random which means its not very random. These names should never be used as any sort of unique id. The names are mostly applicable for small lists of ephemeral objects that you want to have easy to remember identifiers for.

Seeds** can be used to generate the same name for the same seed:
```javascript
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
```
`**`(Antti Sykäri's algorithm is used for seedable pseudo random number generator)

You can pass your own custom random number generator, by supplying an object with a method `random` method (that returns values greater than or equal to 0 and less than 1):
```javascript
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 names generations
dockerNames.random_number_generator = {random : () => ((Math.random() + Math.random()) / 2)};
console.log(dockerNames.getRandomName());
console.log(dockerNames.getRandomName());
```

### Word Lists

This module exports the full docker name lists as two arrays.
Expand All @@ -37,4 +57,4 @@ dockerNames.adjectives = Array('admiring', 'adoring'...);

// This contains all surnames to use as "right words"
dockerNames.surnames = Array('albattani', 'allen' ...);
```
```
Loading