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

toosoon-prng

v5.0.0

Published

This project provides PRNG functions for generating pseudo-random values using a seed-based approach

Readme

TOOSOON Pseudo-Random Number Generator (PRNG)

This project provides PRNG functions for generating pseudo-random values using a seed-based approach. These are particularly useful for applications requiring deterministic randomization, such as procedural generation or simulations.

NPM

Installation

Yarn:

$ yarn add toosoon-prng

NPM:

$ npm install toosoon-prng

Usage

Using default PRNG instance.

import prng from 'toosoon-prng';

prng.setSeed('seed');

prng.randomFloat('angle', 0, Math.PI); // Pseudo-random number in the interval [0, PI)

Using PRNG class constructor.

import { PRNG } from 'toosoon-prng';

const prng = new PRNG('seed');

prng.randomFloat('angle', 0, Math.PI); // Pseudo-random number in the interval [0, PI)

API

PRNG

Utility class for generating pseudo-random values.

Types

type Seed = string | number;

type Generator = (...hashes: number[]) => number;

Constructor

| Parameter | Type | Default | Description | | ----------- | ----------- | ------- | ------------------------------------------------------ | | [seed] | Seed | | Seed string used for pseudo-random generations. | | [generator] | Generator | sfc32 | Generator function used for pseudo-random generations. |

Properties

.seed

Seed string used for pseudo-random generations.

PRNG.seed: string;
.generator

Generator function used for pseudo-random generations.

PRNG.generator: Generator;

Methods

.setSeed(seed)

Set the PRNG instance seed.

  • seed
PRNG.setSeed(seed: Seed): void;
.random(subseed)

Generate a pseudo-random number between 0 and 1 (0 inclusive, 1 exclusive). Pseudo-random equivalent of Math.random().

  • subseed
PRNG.random(subseed: Seed): number;
.randomBoolean(subseed, probability?)

Generate a pseudo-random boolean (true or false).

  • subseed
  • [probability=0.5]: Probability to get true.
PRNG.randomBoolean(subseed: Seed, probability?: number): boolean;
.randomSign(subseed, probability?)

Generate a pseudo-random sign (1 or -1).

  • subseed
  • [probability=0.5]: Probability to get 1.
PRNG.randomSign(subseed: Seed, probability?: number): number;
.randomFloat(subseed, min?, max?, precision?)

Generate a pseudo-random floating-point number within a specified range.

  • subseed
  • [min=0]: Minimum boundary.
  • [max=1]: Maximum boundary.
  • [precison=2]: Number of digits after the decimal point.
PRNG.randomFloat(subseed: Seed, min?: number, max?: number1, precision?: number): number;
.randomInt(subseed, min, max)

Generate a pseudo-random integer number within a specified range.

  • subseed
  • min: Minimum boundary.
  • max: Maximum boundary.
PRNG.randomInt(subseed: Seed, min: number, max: number): void;
.randomHexColor(subseed)

Generate a pseudo-random hexadecimal color.

  • subseed
PRNG.randomHexColor(subseed: Seed): string;
.randomItem(subseed, array)

Pseudo-randomly pick an item from an array.

  • subseed
  • array: Array to pick the item from.
PRNG.randomItem<T>(subseed: Seed, array: T[]): T | undefined;
.randomObjectProperty(subseed, object)

Pseudo-randomly pick a property value from an object.

  • subseed
  • object: Object to pick the property from.
PRNG.randomObjectProperty<T>(subseed: Seed, object: Record<string, T>): T | undefined;
.randomIndex(subseed, weights)

Select a pseudo-random index from an array of weighted items.

  • subseed
  • weights: Array of weights.
PRNG.randomIndex(subseed: Seed, weights: number[]): number;
.randomGaussian(subseed, mean?, spread?)

Generate a pseudo-random number fitting a Gaussian (normal) distribution.

  • subseed
  • [mean=0]: Mean (central) value of the distribution.
  • [spread=1]: Spread (standard deviation) of the distribution.
PRNG.randomGaussian(subseed: Seed, mean?: number, spread?: number): number;

Generators

By default, the library is using SplitMix32 generator for generating the pseudo-random values but it is possible to change the generator used by one of the following:

  • sfc32: Simple Fast Counter, Generator with a 128-bit state.
  • jsf32: Jenkins' Small Fast, Generator with a 128-bit state.
  • xoshiro128ss: xoshiro128**, Generator with a 128-bit state.
  • mulberry32: Mulberry32, Generator with a 32-bit state.
  • splitmix32: SplitMix32, Generator with a 32-bit state.
import { PRNG, sfc32 } from 'toosoon-prng';

const prng = new PRNG('seed', { generator: sfc32 });

Utils

randomSeed(length?)

Generate a random string that can be used as a seed.

  • [length=64]: Length of the generated seed string.
randomSeed(length?: number): string;

Constants

DEFAULT_SEED

License

MIT License, see LICENSE for details.