pcg-gen
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

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
}

Package Sidebar

Install

npm i pcg-gen

Weekly Downloads

1

Version

1.1.0

License

MIT

Unpacked Size

5.74 kB

Total Files

5

Last publish

Collaborators

  • philihp