Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/susisu/tf-random.js
Splittable pseudorandom number generator
https://github.com/susisu/tf-random.js
Last synced: 1 day ago
JSON representation
Splittable pseudorandom number generator
- Host: GitHub
- URL: https://github.com/susisu/tf-random.js
- Owner: susisu
- License: mit
- Created: 2018-11-21T14:27:38.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-12-19T06:43:45.000Z (almost 3 years ago)
- Last Synced: 2024-10-13T23:32:07.914Z (25 days ago)
- Language: TypeScript
- Size: 425 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# tf-random.js
[![CI](https://github.com/susisu/tf-random.js/workflows/CI/badge.svg)](https://github.com/susisu/tf-random.js/actions?query=workflow%3ACI)Pure JavaScript port of [tf-random](http://hackage.haskell.org/package/tf-random-0.5), splittable pseudorandom number generator.
## Installation
``` shell
# npm
npm i @susisu/tf-random
# yarn
yarn add @susisu/tf-random
```## Usage
``` javascript
import { TFGen } from "@susisu/tf-random";// Initialize a generator.
const gen = TFGen.init();// Call `next` to generate a random number (32-bit signed integer) and a new generator.
const [x, nextGen] = gen.next();// Call `split` to derive two effectively independent generators.
const [gen1, gen2] = nextGen.split();
```You can also call `gen.splitn(n, i)` to derive `2 ** n` independent generators and obtain `i`th of them.
The package also provides some utility functions `random`, `randomInt32`, `randomInt32R`, etc. for generating random numbers.
## License
[MIT License](http://opensource.org/licenses/mit-license.php)## Author
Susisu ([GitHub](https://github.com/susisu), [Twitter](https://twitter.com/susisu2413))