Skip to content

kripod/pcg.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors