Chance.js is a comprehensive utility library designed for generating a wide variety of random data in JavaScript environments, including Node.js and browsers. It currently stands at stable version 1.1.13 and has a generally infrequent release cadence, with major updates occurring as needed for new features or critical bug fixes rather than on a fixed schedule. Its core differentiator is its foundation on the Mersenne Twister algorithm, which allows for repeatable pseudo-random sequences when seeded, making it invaluable for testing, data simulation, and reproducible scenarios. The library provides generators for basic types like numbers, characters, and strings, as well as complex data such as names, addresses, dice rolls, and geographical coordinates, distinguishing itself by its breadth and optional determinism.
npm install chanceVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to instantiate Chance, generate various types of random data, and critically, how to use seeding to achieve reproducible random sequences for testing or deterministic data generation.
Use `const chance = new Chance();` instead of `const chance = Chance();`.
For non-reproducible randomness, instantiate without a seed: `const chance = new Chance();`. For environment-driven seeding, use `new Chance(process.env.RANDOM_SEED ?? undefined);`.
For ESM projects, use `import Chance from 'chance';`. For CommonJS projects, use `const Chance = require('chance');`. Configure your `package.json` `type` field and build tools appropriately.Use `const chance = new Chance();` to instantiate the Chance generator.
Ensure you have `import Chance from 'chance';` (ESM) or `const Chance = require('chance');` (CJS) at the top of your file, or that the `<script>` tag is loaded in a browser environment.Change the import to `import Chance from 'chance';`. If you truly need CommonJS, ensure your file is treated as CJS (e.g., using `.cjs` extension or `type: 'commonjs'` in `package.json`).
No dependency data recorded yet.