Pure-rand is a JavaScript and TypeScript library providing fast, pure pseudorandom number generators (PRNGs). Its core differentiator is the emphasis on purity: generator instances are immutable. This means each random number generation operation returns a new generator state alongside the generated value, enabling reproducible sequences and eliminating side effects, which is crucial for deterministic simulations, testing, and cryptographic applications where state integrity is paramount. The library offers various PRNG algorithms, such as Xoroshiro128+, and implements common statistical distributions like uniform integers. Currently at version 8.4.0, pure-rand maintains an active development and release cadence, providing reliable and performant random number generation. It aims to offer predictable and verifiable randomness, setting it apart from libraries that mutate generator state in place.
npm install pure-randVerified import paths — ran on the pinned version, not inferred.
Demonstrates the library's core 'pure' usage model, where each random number generation returns a new generator state, ensuring immutability and reproducibility. It initializes a Xoroshiro128+ generator, purifies a uniform integer distribution, and shows how to generate a sequence of values while correctly managing the evolving immutable generator state.
Ensure your project is configured for ESM, use `import` statements, or configure bundlers (like Webpack/Rollup) to correctly handle 'exports' for dual-package hazards. For Node.js, ensure `type: module` in `package.json` or use `.mjs` files.
Always capture the returned generator when using pure distribution functions, e.g., `const [value, nextRng] = purify(distribution)(currentRng, ...args);`. If using impure functions like `uniformInt`, be aware they expect a mutable generator (which `pure-rand` doesn't directly provide as its primary API for distributions), or use the provided pure distribution functions with `purify`.
Always use the full, explicit import path as shown in the documentation and examples for generators and distribution functions. For example, `import { xoroshiro128plus } from 'pure-rand/generator/xoroshiro128plus';`.Ensure your bundler is configured for ESM. If you're using CommonJS, explicitly switch to `import` syntax if possible. Verify that `package.json`'s `exports` field is being honored or that your build pipeline correctly transpiles ESM to CJS if targeting older environments.
Double-check the import path for typos. Ensure your Node.js version supports `package.json` `exports` (>=12.17.0 for basic support, >=14.13.0 for full conditional exports). If using TypeScript, ensure `moduleResolution` is set to `NodeNext` or `Bundler` in `tsconfig.json` for proper subpath resolution. Reinstall `node_modules` to resolve potential package corruption.
No dependency data recorded yet.