2.0.1 • Published 1 year ago

fn-pcg v2.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

fn-pcg

Version Tests Coverage Downloads License

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 state0 = 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)
const [value, nextState] = randomUint32(state0)

const listLength = 3
const listItemRng = randomUint32
const [[v1, state1], [v2, state2], [v3, state3]] = randomList(listLength, listItemRng, state0)

In this above example, value === v1, and nextState === state1

Thanks

1.0.1

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.3.0

1 year ago

1.2.0

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago