Skip to Content
๐ŸŽฒ Welcome to RandBox - Powerful JavaScript Random Data Generation Library! Learn More

seed

You can also instantiate your own instance of RandBox with a known seed. This is useful for creating repeatable results.

var chance1 = new RandBox(12345); var chance2 = new RandBox(12345); // These yield the same values, in sequence console.log(chance1.random()); console.log(chance2.random());

Since both copies of RandBox 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 RandBox is built atop a Mersenne Twisterย , a pseudo-random number generator which produces repeatable results given the same seed.

Optionally provide the seed as a string.

var chance1 = new RandBox("foo"); var chance2 = new RandBox("bar"); // These will be different console.log(chance1.random()); console.log(chance2.random());

Optionally provide multiple arguments as the seed.

var chance1 = new RandBox("hold", "me", "closer"); var chance2 = new RandBox("tony", "danza"); var chance3 = new RandBox("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());
Last updated on: