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

procedural-rng

v0.0.5

Published

A collection of procedural random number generators (prng) written in TypeScript

Downloads

12

Readme

procedural-rng.js

procedural-rng.js collection of procedural random number generators (prng) written in TypeScript.

Unlike the built in Math.random(), these generators can be provided an initial seed value, allowing for reproducable and predictable results.

Please note: These generators are NOT cryptographically secure and should not be used in cases where strong cryptographic randomness is needed. If strong crypographic properties are needed, such as when generating certificates or authentication tokens, please refer to JavaScript's built-in Crypto interface

Usage

Setting up the generator

import {Random, MT19937} from "procedural-rng";

const seed = 1729;
const generator = new MT19937(seed); // Mersenne twister
const r = new Random(generator);

Generating random values

// Random int between 0-99 (inclusive)
const random_int = r.below(100);

// Random float between 0 (inclusive) and 1 (exclusive) (same as Math.random())
const random_float = r.float();

Other utility functions

console.log(`Dice roll: You rolled a ${r.range({start: 1, stop: 7})}`); 

console.log(`Coin flip: You flipped a ${r.choice(['Heads', 'Tails'])}`);

Array functions

const playlist = [
	{name: "The Sound of Silence", year: 1964, artist: "Simon & Garfunkel"},
	{name: "Life on Mars?", year: 1973, artist: "David Bowie"},
	{name: "Stairway to Heaven", year: 1971, artist: "Led Zeppelin"},
	{name: "Sympathy For The Devil", year: 1969, artist: "The Rolling Stones"},
	{name: "Who Are You", year: 1978, artist: "The Who"}
];

r.shuffleInPlace(playlist);
console.log(playlist);

const suits = ["Hearts", "Spades", "Diamonds", "Clubs"];
const values = ["Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"];

const cards = suits.map(s => values.map(v => `${v} of ${s}`)).flat();
const draw = r.choice(cards);
console.log(draw);

Types of generators

import {MT19937, LCRNG, Xorshift32, Xorshift128} from "procedural-rng"

{
	const lcrng = new LCRNG(54321, {
		// Newlib, Musl parameters taken from
		// https://en.wikipedia.org/wiki/Linear_congruential_generator
		m: BigInt(2)**BigInt(64),         // Modulus
		a: BigInt("6364136223846793005"), // multiplier
		c: BigInt("1"),                   // increment
		w: 32, // Width in bits of the output
		s: 32, // Shift in bits of the output
		// Returning 32 bits after shifting 32 bits = bits 63..32
	});
	const r = new Random(lcrng);
}

{
	// Params based on older versions of Java's java.util.random
	const lcrng = new LCRNG.JavaRandom(12345);
	const r = new Random(lcrng);
}

{
	const xorshift32 = new Xorshift32(192837465);
	const r = new Random(xorshift32);
}

{
	// Pameters x, y, z, and w of the xorshift128 algorithm (all are optional)
	// The first param is Date.now() by default, as is the other generators
	// The other three values are derived from hashes of value before them
	const xorshift128 = new Xorshift128(123456789, 362436069, 521288629, 88675123);
	const r = new Random(xorshift128);
}