ml-xsadd
TypeScript icon, indicating that this package has built-in type declarations

3.0.1 • Public • Published

ml-xsadd

Maintained by Zakodium

NPM version build status npm download

JavaScript implementation of the XORSHIFT-ADD (XSadd) pseudo random number generator.

Based on the C code from https://github.com/MersenneTwister-Lab/XSadd.

Installation

$ npm install ml-xsadd

API

const { XSadd } = require("ml-xsadd");

const gen = new XSadd();
const number = gen.getFloat();

new XSadd([seed])

Creates a new XSadd instance. Seed is an optional integer that defaults to Date.now().

getUint32()

Returns a 32-bit integer r (0 <= r < 2^32).

getFloat()

Returns a floating point number r (0.0 <= r < 1.0).

random()

Like getFloat() but dynamically bound to the XSadd instance.
You can use this function externally, like Math.random:

const xsadd = new XSadd();
const random = xsadd.random;
const number = random();

init(seed)

Reinitialize the generator with a new seed.

LICENSE

MIT

Package Sidebar

Install

npm i ml-xsadd

Weekly Downloads

88,499

Version

3.0.1

License

MIT

Unpacked Size

22.2 kB

Total Files

22

Last publish

Collaborators

  • stropitek
  • targos
  • lpatiny
  • mljs-bot