kripod / pcg.js

A functional implementation of the PCG family random number generators, written in JavaScript.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pcg.js

NPM Travis CI Codecov

A functional implementation of the PCG family random number generators, written in JavaScript.

Getting started

To achieve frictionless reproducibility of random output results, immutable objects are used throughout the project.

Firstly, create a random number engine:

import { createPcg32 } from 'pcg';

const advancedOptions = {};
const initState = 42;
const initStreamId = 54;
const pcg = createPcg32(advancedOptions, initState, initStreamId);

After that, random outputs can be generated by calling appropriate functions as shown below:

import { nextState, prevState, randomInt, randomList } from 'pcg';

const randomUint32 = randomInt(0, (2 ** 32) - 1);
let [value, nextPcg] = randomUint32(pcg);

const listLength = 6;
const listItemRng = randomUint32;
[value, nextPcg] = randomList(listLength, listItemRng, pcg);

About

A functional implementation of the PCG family random number generators, written in JavaScript.

License:MIT License


Languages

Language:JavaScript 100.0%