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 🙏

© 2025 – Pkg Stats / Ryan Hefner

rndlib

v0.9.3

Published

Easy to use randomizer functions with TypeScript support

Downloads

44

Readme

RNDLIB

Randomization utils for simpler usage.

Mission

To create a library of simple to use randomization functions. Not the fastest, not the fanciests, but good enough for most use cases and easy to understand.

Basic Randomizers

These functions are easy to use and understand will cover most use cases.

rnd()

Used to pick to random number between two numbers:

// Generate a random number between 1 and 10
const result: number = rnd(1, 10);

// Generate a random number between 1 and 10
const result: number = rnd(10);

chance()

Succeed or fail based on a precentage

// 50% chance to return true or false
const willWork: boolean = chance(50);

// 10% chance of succcess
const liveto100: boolean = chance(10);

padrnd()

Return a string with padded zeros. The length of the pad is equal to the length of the max value.

// Return a string between 001-100
const value: string = padrnd(1, 100);

// Return a string between 01-10
const value: string = padrnd(10);

nrnd()

Return random value between min and max but the results are normalized. The higher the ramp value is (between 0-10, default is 5), more skewed the results are towards midrange (gauss anyone?). 0 is same as rnd().

// Return a value between 1 and 100, where values closer to 50 are much more common.
const val: number = nrnd(1, 100);

// When ramp value is increased even more values are closer to 50
const val: number = nrnd(1, 100, 8);

// When ramp value goes down the curve becomes more flat
const val: number = nrd(1, 100, 3);

Array randomizers

Functions to be used with Arrays

arnd()

Return a random value from the Array.

const val: string = arnd<string>(["A", "B", "C", "D"]);

arnds()

Return one or more values from the array. This can be set to only return a single value once.

// Return two values from array. Valid responses are for example ["A", "C"] or ["B", "B"]
const vals: string[] = arnds(["A", "B", "C", "D"], 2);

// Return 3 unique values from the provided array.
const vals: number[] = arnds([1, 2, 3, 4, 5, 6], 3, true);

shuffle()

Return a shallow copy the provided array where the value order has been randomized.

// Same values, new order
const arr: number[] = shuffle<number>([1, 2, 3, 4, 5, 6]);

// This is only a shallow copy so objects in the array are not copied
const arr: MyData = shuffle<MyData>([{ a: "foo" }, { a: "bar" }]);

Dice functions

Ready to run dice functions with familiar names!

Simple dice functions

All the usual suspects have their own functions. Each function returns an array of results. One result for each die rolled.

import { Dice } from "rndlib";

// Return a random value between 1 and 6
const val: number[] = Dice.d6();

// Roll 2 ten sided dice
const val: number[] = Dice.d10(2);

roll()

Roll function is used to convert string based dice rolls like 2d6 and 3d4+2 to results directly. roll() funciton returns an interface that has thee values in it:

  • sum: contains the sum of all the dice rolls and the added bonus.
  • rolls: is an array of roll results, one number for each die
  • dieType: contains the die type as a number, so d6 would have 6 and d20 would contain 20.
// This will roll two 6 sided dice and sum their results together resulting a value between 2 and 12.
const val: DiceResults = Dice.roll("2d6");

// This will return a sum value between 6 and 33.
const val: DiceResults = Dice.roll("3d10+3");

// This will roll 3 six sided dice, sum their result total and then substract 2 from it resulting in a value between 1 and 16.
const val: DiceResults = Dice.roll("3d6-2");

Utility functions

Collection of functions to handle randomized results

successPool()

Get the number of results that is equal or higher than the threshold value. Values be provided as an array of numbers or as a Diceresult. If Diceresult is used all bonus modifiers are ignored.

// All values of 6 or more are successes
const successesA: number = successPool(6, d10(7));
const successesB: number = successPool(6, Dice.roll("7d10"));
const successesC: number = successPool(6, [1, 8, 6, 3, 9, 4, 6]); // Will return 4

sumPool()

Will return a sum of array of numbers or a DiceResult. When DiceResult is provided this does not take into account any modifiers, making is a useful tool for gettin sum of actual results without bonuses.

const totalA: number = sumPool([1, 2, 3, 4]); // result is 10
const totalB: number = sumPool(d6(4));
const totalC: number = sumPool(Dice.roll("4d6"));
const totalD: number = sumPool(Dice.roll("2d6+2")); // value is between 2 and 12 not 4 and 14.