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

@chaisser/random-seed

v1.0.1

Published

Seeded random number generator

Downloads

67

Readme

@chaisser/random-seed

Seeded random number generator

Deterministic, reproducible random number generation using a seed. Generate numbers, booleans, dates, strings, UUIDs, colors, coordinates, and more — all reproducible from a seed value.


Installation

npm install @chaisser/random-seed
# or
yarn add @chaisser/random-seed
# or
pnpm add @chaisser/random-seed

Quick Start

import { createRNG } from '@chaisser/random-seed';

const rng = createRNG(42);

rng.nextInt(1, 100);        // deterministic integer
rng.nextFloat(0, 10);       // deterministic float
rng.nextBool(0.3);          // deterministic boolean
rng.uuid();                 // deterministic UUID
rng.shuffle([1, 2, 3, 4]); // deterministic shuffle
rng.pick(['a', 'b', 'c']); // deterministic pick

// Same seed always produces same sequence
const a = createRNG(42);
const b = createRNG(42);
a.nextInt(1, 100) === b.nextInt(1, 100); // true

API Reference

createRNG(seed?)

Creates a seeded random number generator. Accepts number or string seeds. Returns a SeededRNG object.

RNG Methods

| Method | Description | |--------|-------------| | next() | Float in [0, 1) | | nextInt(min, max) | Integer in [min, max] | | nextFloat(min?, max?) | Float in [min, max] (default 0, 1) | | nextBool(probability?) | Boolean (default p=0.5) | | nextDate(start, end) | Random Date in range | | pick(array) | Random element | | pickMultiple(array, count) | Multiple random elements (with replacement) | | shuffle(array) | Shuffled copy (Fisher-Yates) | | weighted(items) | Weighted random pick | | uuid() | UUID v4 string | | hex(bytes?) | Hex string (default 8 bytes = 16 chars) | | alpha(length) | Alphabetic string | | alphanumeric(length) | Alphanumeric string | | reset() | Reset to initial seed state | | getSeed() | Return the seed value |

One-shot Helpers

Each method has a seeded* helper that creates a temporary RNG, calls once, and returns:

| Function | Description | |----------|-------------| | seededRandom(seed?) | Single float [0, 1) | | seededInt(min, max, seed?) | Single int | | seededFloat(min, max, seed?) | Single float | | seededBool(probability, seed?) | Single bool | | seededPick(array, seed?) | Single pick | | seededPickMultiple(array, count, seed?) | Multiple picks | | seededShuffle(array, seed?) | Shuffled copy | | seededWeighted(items, seed?) | Weighted pick | | seededUuid(seed?) | UUID | | seededHex(bytes, seed?) | Hex string | | seededAlpha(length, seed?) | Alpha string | | seededAlphanumeric(length, seed?) | Alphanumeric string | | seededDate(start, end, seed?) | Random date |

Distributions

| Function | Description | |----------|-------------| | gaussian(mean?, stdDev?, rng?) | Box-Muller normal distribution | | gaussianArray(count, mean?, stdDev?, rng?) | Array of gaussian values | | exponential(lambda?, rng?) | Exponential distribution |

Array Generators

| Function | Description | |----------|-------------| | intArray(min, max, count, rng?) | Array of random ints | | floatArray(min, max, count, rng?) | Array of random floats | | boolArray(count, probability?, rng?) | Array of random bools | | uniqueInts(min, max, count, rng?) | Array of unique random ints |

Color

| Function | Description | |----------|-------------| | randomColor(rng?) | Hex color string (#rrggbb) | | randomRgb(rng?) | { r, g, b } (0-255) | | randomHsl(rng?) | { h, s, l } (h: 0-360, s/l: 0-100) |

Coordinates & Network

| Function | Description | |----------|-------------| | randomCoordinate(latRange, lngRange, rng?) | { lat, lng } | | randomIP(rng?) | IPv4 string |

Dice

| Function | Description | |----------|-------------| | randomDice(sides?, rng?) | Roll one die (default 6 sides) | | randomCoin(rng?) | 'heads' or 'tails' | | rollDice(count, sides, rng?) | Roll N dice | | rollDiceSum(count, sides, rng?) | Sum of N dice |


Examples

Reproducible Test Data

import { createRNG } from '@chaisser/random-seed';

function generateTestUsers(count: number, seed = 42) {
  const rng = createRNG(seed);
  return Array.from({ length: count }, (_, i) => ({
    id: i + 1,
    name: rng.alpha(8),
    score: rng.nextInt(0, 100),
    active: rng.nextBool(0.7)
  }));
}

// Same data every time
const users = generateTestUsers(100);

Shuffle a Playlist

import { createRNG } from '@chaisser/random-seed';

function shufflePlaylist(tracks: string[], seed: number) {
  return createRNG(seed).shuffle(tracks);
}

// Same seed = same order
const shuffled = shufflePlaylist(['song1', 'song2', 'song3', 'song4'], 42);

Weighted Random Selection

import { createRNG } from '@chaisser/random-seed';

const rng = createRNG(42);

const loot = rng.weighted([
  { value: 'common', weight: 60 },
  { value: 'uncommon', weight: 25 },
  { value: 'rare', weight: 10 },
  { value: 'legendary', weight: 5 }
]);

Generate Test IDs

import { createRNG } from '@chaisser/random-seed';

const rng = createRNG(42);

const id1 = rng.uuid();       // 'a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d'
const id2 = rng.hex(16);      // 32-char hex string
const code = rng.alphanumeric(8); // 8-char alphanumeric

Statistical Distributions

import { createRNG, gaussian, intArray } from '@chaisser/random-seed';

const rng = createRNG(42);

// Normal distribution (mean=100, stdDev=15)
const iq = gaussian(100, 15, rng);

// 1000 IQ scores
const scores = gaussianArray(1000, 100, 15, rng);

// 10 unique lottery numbers
const lottery = intArray(1, 49, 6, rng);

License

MIT