npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

pcg

v3.0.0

Published

A functional typescript implementation of the PCG family random number generators

Downloads

1,235,159

Readme

pcg

A functional implementation of the PCG family random number generators, written in TypeScript. Runs are reproducible, replayable, and rewindable. State can be serialized and reconstituted later. Ships dual ESM/CJS builds and TypeScript types. Runs on Node 18+, Bun, Deno, and modern browsers.

Version Tests Coverage Bundle size Downloads License

Quick start

import { createPcg32, nextState, randomInt, randomList } from 'pcg'

// A stream id picks *which* unique periodic series of entropy to use.
// The seed picks *where* in that series to start.
const state0 = createPcg32({}, 42, 54)

const randomUint32 = randomInt(0, 2 ** 32 - 1)
const [value, state1] = randomUint32(state0)

const list = randomList(3, randomUint32, state0)
// list === [[v0, s0], [v1, s1], [v2, s2]] — value === v0, state1 === s0

state0 is never mutated. Pass state1 into the next call to continue the stream, or hold onto state0 and replay it. Persist a state with JSON.stringify(state0) and rehydrate with JSON.parse.

API

Initialize state

createPcg32(options, seed, streamId) → PCGState

import { createPcg32, OutputFnType, StreamScheme } from 'pcg'

const state = createPcg32(
  {
    outputFnType: OutputFnType.XSH_RR,
    streamScheme: StreamScheme.SETSEQ
  },
  42,
  54
)

Output functions (OutputFnType) — different ways of permuting the 64-bit state into a 32-bit word.

| Variant | Notes | | --- | --- | | XSH_RR (default) | xor-shift high, random rotate. The PCG default; good all-rounder. | | XSH_RS | xor-shift high, random shift. Slightly faster, marginally weaker. | | XSL_RR | xor-shift low, random rotate. | | RXS_M_XS | random xor-shift, multiply, xor-shift. Strongest of the four; slightly slower. |

Stream schemes (StreamScheme) — how the increment is chosen each step.

| Variant | Notes | | --- | --- | | SETSEQ (default) | Per-state stream id; lets independent streams coexist from one seed family. | | ONESEQ | Single fixed increment; ignores streamId. | | MCG | Multiplicative congruential generator (no increment). Fastest, but period halved. |

Drawing values

  • randomInt(min, max, state) → [number, PCGState] — uniform integer in [min, max). Curried so const random = randomInt(min, max); random(state) also works.
  • randomList(length, rng, state) → [value, PCGState][] — runs rng length times, threading the state. Also fully curried.
  • getOutput(state) → number — output at the current state without advance.

Advancing state

  • nextState(state) → PCGState — advance by 1.
  • prevState(state) → PCGState — rewind by 1. Unsupported by sfc32.
  • stepState(delta, state) → PCGState — jump ahead or back where delta is a signed integer. O(log Δ) via Brown's jump-ahead algorithm for PCG.

Types

PCGState, Uint64, RandomFn<T>, CreatePcgOptions, OutputFn, SchemeFn, PCGVariant are all exported. State is { state: Uint64, streamId: Uint64, variant, outputFnType, streamScheme } where Uint64 is { hi: number, lo: number }.

Migrating from 1.x

PCGState is no longer a bigint. The 64-bit halves are now { hi: number, lo:number } objects, so serialization with JSON.stringify round-trips cleanly.

See CHANGELOG.md for the full set of changes.

Thanks