pcg-gen

v1.0.0
A permuted congruential generator generator
prng pcg random generator

Version Tests Coverage Status Downloads License

Permuted Congruential Generator Generator

A permuted congruential generator (PCG) is a pseudorandom number generation algorithm developed in 2014 which applies an output permutation function to improve the statistical properties of a modulo-2^n linear congruential generator. It achieves excellent statistical performance with small and fast code, and small state size.

This implementation uses a Javascript generator function, because we can, and it also justifies the redundant package name.

There are reasons why this might be better.

Install

npm install --save pcg-gen

Usage

import { pcggen } from 'pcg-gen'

const rand = pcggen(42n)
const { value: r1 } = randomizer.next()
// r1 <- 1292176121501498n
const { value: r2 } = randomizer.next()
// r2 <- 11541586741780280317n

Because pcggen returns an iterable, you can use it in a for...of loop if that's your kink.

for (const n of rand) {
  console.log(n)
  if (n > 1000000) break
}

Metadata

  • MIT
  • Whatever
  • Philihp Busby
  • released 11/8/2022

Downloads

Maintainers