Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ml-xsadd

mljs486.5kMIT3.0.1TypeScript support: included

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

xsadd, xorshift, add, pseudo, random, number, generator, machine, learning

readme

ml-xsadd

Zakodium logo

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

changelog

Changelog

3.0.1 (2024-10-18)

Bug Fixes

  • main points to /lib/index.js (a509dde)

3.0.0 (2024-10-17)

⚠ BREAKING CHANGES

  • Remove default export. You need to "import {XSadd} from 'xsadd'"

Features

  • Remove default export. You need to "import {XSadd} from 'xsadd'" (ac4275b)

2.0.0 (2018-08-11)

Features

  • refactor to have a ES module build and use TypeScript (#3) (b326a75), closes #2

BREAKING CHANGES

  • The initialization now throws if the seed is not an integer. Stop supporting Node 4.

1.0.0 / 2015-07-23

  • first release