Skip to content

susisu/tf-random.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

1a18b85 · Dec 19, 2021

History

90 Commits
Dec 19, 2021
Oct 24, 2020
Dec 19, 2021
Oct 24, 2020
Dec 19, 2021
Oct 24, 2020
Dec 19, 2021
Oct 24, 2020
Oct 24, 2020
Nov 6, 2020
Oct 24, 2020
Dec 19, 2021
Oct 24, 2020
Oct 24, 2020
Oct 24, 2020
Oct 24, 2020
Dec 19, 2021

Repository files navigation

tf-random.js

CI

Pure JavaScript port of tf-random, splittable pseudorandom number generator.

Installation

# npm
npm i @susisu/tf-random
# yarn
yarn add @susisu/tf-random

Usage

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 ith of them.

The package also provides some utility functions random, randomInt32, randomInt32R, etc. for generating random numbers.

License

MIT License

Author

Susisu (GitHub, Twitter)