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

pdrng

v1.0.0

Published

Pseudo Deterministic Random Number Generator - seed-based deterministic number generation

Downloads

6

Readme

pdrng npm version npm downloads CI Open Source Love Semver License LinkedIn

pdrng

Pseudo Deterministic Random Number Generator — seed-based deterministic number generation.

A JavaScript library for generating deterministic outputs based on a numeric seed. Given the same seed, every function produces the same result every time. Useful for testing, simulations, reproducible demos, and seeded content generation.

Default seed: 814

Install

npm install pdrng

Quick Start

import pdrng from 'pdrng';

pdrng()        // 814
pdrng(1)       // 8
pdrng(6)       // 814814
pdrng.coin()   // "tails"
pdrng.dice()   // 4
pdrng.card()   // "8 of Diamonds"

API

Core

pdrng(digits?, options?)

Generate a deterministic number with the specified number of digits.

pdrng()           // 814 (default: 3 digits)
pdrng(1)          // 8
pdrng(2)          // 14
pdrng(4)          // 8148
pdrng(5)          // 81414
pdrng(6)          // 814814

Utilities

float(precision?, options?)

float()           // 0.814814
float(3)          // 0.814

range(min, max, options?)

range(1, 100)     // 14

array(count, digits?, options?)

array(3, 2)       // [14, 46, 78] (sub-seeds per element)

uuid(options?)

uuid()            // deterministic UUID v4 format

oddOrEven(options?)

oddOrEven()       // "even"

redOrBlack(options?)

redOrBlack()      // "red"

randomSeed()

Generate a random seed using crypto.getRandomValues (with Math.random fallback).

randomSeed()      // e.g. 3847291056 (different each call)

Simulation Functions

coin(options?)

Deterministic coin flip.

coin()            // "tails"

dice(sides?, options?)

Deterministic die result.

dice()            // 4 (6-sided)
dice(20)          // 14

card(options?)

Deterministic playing card draw.

card()            // "8 of Diamonds"

rps(options?)

Deterministic rock-paper-scissors.

rps()             // "scissors"

magic8(options?)

Deterministic 8-ball response.

magic8()          // "Reply hazy, try again."

zodiac(options?)

Deterministic zodiac sign.

zodiac()          // "Gemini"

tarot(options?)

Deterministic tarot card.

tarot()           // "The Magician"

fortune(options?)

Deterministic fortune message.

fortune()         // "The answer you seek was never in doubt."

spin(array, options?)

Deterministic selection from an array.

spin(['a', 'b', 'c', 'd'])  // "c"

roll(notation, options?)

Deterministic dice notation result (tabletop RPG style).

roll('2d6+3')     // { rolls: [5, 1], modifier: 3, total: 9 }

bingo(options?)

Deterministic bingo call.

bingo()           // "B-14"

color(options?)

Deterministic hex color.

color()           // "#a81414"

roulette(options?)

Deterministic number with color and parity.

roulette()        // { number: 14, color: "red", parity: "even" }

Custom Seeds

Every function accepts an options object with a seed property:

import { coin, dice, card } from 'pdrng';

coin({ seed: 42 })        // "heads"
dice(6, { seed: 42 })     // 4
card({ seed: 'brian' })   // deterministic card from text seed

Text seeds are converted using a rolling XOR hash, designed so that "brian" maps to seed 814:

pdrng(3, { seed: 'brian' })  // 814 (same as default!)
pdrng(4, { seed: 'brian' })  // 8148

Random Seeds

While pdrng is deterministic by design, you can use random input to get non-deterministic behavior. Pass Math.random(), crypto.getRandomValues(), or use the built-in randomSeed() helper:

import { coin, dice, randomSeed } from 'pdrng';

// Built-in helper (uses crypto.getRandomValues for real entropy)
coin({ seed: randomSeed() })      // different each call

// Math.random() works directly as a seed
dice(6, { seed: Math.random() })  // different each call

Imports

// Default import (with all methods attached)
import pdrng from 'pdrng';
pdrng.coin();

// Named imports
import { coin, dice, card, roll } from 'pdrng';
coin();

Requirements

  • Node.js 18+
  • ESM only (import/export)

License

MIT