From 46e43f4bde4a35785b4997b81e86cd19f046b69b Mon Sep 17 00:00:00 2001 From: Minteck Date: Tue, 21 Dec 2021 16:52:28 +0100 Subject: Commit --- src/node_modules/chance/docs/usage/seed.md | 49 ++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/node_modules/chance/docs/usage/seed.md (limited to 'src/node_modules/chance/docs/usage/seed.md') diff --git a/src/node_modules/chance/docs/usage/seed.md b/src/node_modules/chance/docs/usage/seed.md new file mode 100644 index 0000000..737a91d --- /dev/null +++ b/src/node_modules/chance/docs/usage/seed.md @@ -0,0 +1,49 @@ +# seed + +You can also instantiate your own instance of Chance with a known seed. This is +useful for creating repeatable results. + +```js +var chance1 = new Chance(12345); +var chance2 = new Chance(12345); + +// These yield the same values, in sequence +console.log(chance1.random()); +console.log(chance2.random()); +``` + +Since both copies of Chance had the same seed, they will both generate the same +random number sequence each time they're called. + +This allows for repeatability, if desired. + +This is possible because **Chance** is built atop a [Mersenne Twister][mersenne], +a pseudo-random number generator which produces repeatable results given the same seed. + +Optionally provide the seed as a string. + +```js +var chance1 = new Chance("foo"); +var chance2 = new Chance("bar"); + +// These will be different +console.log(chance1.random()); +console.log(chance2.random()); +``` + +Optionally provide multiple arguments as the seed. + +```js +var chance1 = new Chance("hold", "me", "closer"); +var chance2 = new Chance("tony", "danza"); +var chance3 = new Chance("hold", "me", "closer"); + +// These will be different +console.log(chance1.random()); +console.log(chance2.random()); + +// This will be the same as the value from chance1 above +console.log(chance3.random()); +``` + +[mersenne]: http://en.wikipedia.org/wiki/Mersenne_twister -- cgit