small-prng

A fast, seedable replacement for Math.random().

Usage no npm install needed!

<script type="module">
  import smallPrng from 'https://cdn.skypack.dev/small-prng';
</script>

README

small-prng

A fast, seedable replacement for Math.random().

npm Node.js Build Status Code Coverage Maintainability Dependencies Status MIT licensed

Installation

npm i small-prng

Usage

Exported global function

The seed for the exported function random() is based on process.hrtime() when the module is first required.

const { random } = require('small-prng');

random();

Creating a seeded PRNG

To create a seeded PRNG, use the exported function prng(). Calling prng() without any arguments will use process.hrtime() as the seed.

const { prng } = require('small-prng');

const mySeed = 1;
const random = prng(mySeed);

random();

License

The majority of the code in this repository is released under the MIT license. However, the JavaScript port of Bob Jenkins's small noncryptographic PRNG in src/prng.js is public domain.