https://github.com/mljs/xsadd
JavaScript implementation of the XORSHIFT-ADD (XSadd) pseudo random number generator
https://github.com/mljs/xsadd
Last synced: 2 months ago
JSON representation
JavaScript implementation of the XORSHIFT-ADD (XSadd) pseudo random number generator
- Host: GitHub
- URL: https://github.com/mljs/xsadd
- Owner: mljs
- License: other
- Created: 2015-07-22T12:38:18.000Z (almost 10 years ago)
- Default Branch: main
- Last Pushed: 2024-10-18T07:57:28.000Z (8 months ago)
- Last Synced: 2025-04-01T15:41:45.944Z (3 months ago)
- Language: TypeScript
- Size: 119 KB
- Stars: 2
- Watchers: 11
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# ml-xsadd
![]()
Maintained by Zakodium
[![NPM version][npm-image]][npm-url]
[![build status][ci-image]][ci-url]
[![npm download][download-image]][download-url]
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
```js
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`:```js
const xsadd = new XSadd();
const random = xsadd.random;
const number = random();
```### init(seed)
Reinitialize the generator with a new seed.
## LICENSE
[MIT](./LICENSE)
[npm-image]: https://img.shields.io/npm/v/ml-xsadd.svg?style=flat-square
[npm-url]: https://npmjs.org/package/ml-xsadd
[ci-image]: https://github.com/mljs/xsadd/workflows/Node.js%20CI/badge.svg?branch=main
[ci-url]: https://github.com/mljs/xsadd/actions?query=workflow%3A%22Node.js+CI%22
[download-image]: https://img.shields.io/npm/dm/ml-xsadd.svg?style=flat-square
[download-url]: https://npmjs.org/package/ml-xsadd