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

random-library

v1.0.3

Published

## Overview The Random Library provides a collection of utilities for generating random values, including numbers, colors, strings, and more. It is organized into several modules, each offering specific functionality.

Readme

Random Library API Documentation

Overview

The Random Library provides a collection of utilities for generating random values, including numbers, colors, strings, and more. It is organized into several modules, each offering specific functionality.


Modules

1. Core Utilities

CoreRandom

  • random(n: number = 1, o: number | null = null): number

    • Generates a random number.
    • Parameters:
      • n: Upper limit or lower bound if o is provided.
      • o: Upper bound (optional).
    • Returns: A random number between n and o (or 0 and n if o is not provided).
  • flip(t: number = 0.5): boolean

    • Simulates a coin flip with a given probability.
    • Parameters:
      • t: Probability of returning true (default is 0.5).
    • Returns: true or false.
  • shuffle(arr: any[]): any[]

    • Shuffles an array randomly.
    • Parameters:
      • arr: The array to shuffle.
    • Returns: A new shuffled array.
  • weightedRandom(choices: any[], weights: number[]): any

    • Selects a random item based on weights.
    • Parameters:
      • choices: Array of items to choose from.
      • weights: Array of weights corresponding to each choice.
    • Returns: A randomly selected item.

2. Dice Utilities

DiceRoller

  • die(sides: number): number

    • Rolls a single die with the specified number of sides.
    • Parameters:
      • sides: Number of sides on the die.
    • Returns: A random number between 1 and sides.
  • dieRoll(desc: string): number

    • Rolls dice based on a string description (e.g., 2d6+3).
    • Parameters:
      • desc: Dice roll description.
    • Returns: The total result of the roll.
  • bestOfRolls(n: number, diceType: number, bestN: number): number

    • Rolls multiple dice and selects the best results.
    • Parameters:
      • n: Number of dice to roll.
      • diceType: Number of sides on each die.
      • bestN: Number of best rolls to sum.
    • Returns: The sum of the best rolls.

3. Format Utilities

RandomFormat

  • uuid(): string

    • Generates a random UUID.
    • Returns: A string in UUID format.
  • randomAlphaNumeric(length: number, charset: Charset = "alphanumeric"): string

    • Generates a random string of the specified length and charset.
    • Parameters:
      • length: Length of the string.
      • charset: Character set (alphanumeric, alphabetic, numeric, hexadecimal).
    • Returns: A random string.
  • generatePassword(length: number = 12, uppercase: boolean, lowercase: boolean, numbers: boolean, symbols: boolean): string

    • Generates a random password.
    • Parameters:
      • length: Length of the password.
      • uppercase: Include uppercase letters.
      • lowercase: Include lowercase letters.
      • numbers: Include numbers.
      • symbols: Include symbols.
    • Returns: A random password.
  • randomUsername(): string

    • Generates a random username.
    • Returns: A username in the format AdjectiveNounNumber.

4. Color Utilities

RandomColor

  • randomColor(format: Format = "hex"): string

    • Generates a random color in the specified format.
    • Parameters:
      • format: Color format (hex, rgb, hsl).
    • Returns: A random color.
  • randomColorPalette(count: number = 5, format: Format = "hex"): string[]

    • Generates a palette of random colors.
    • Parameters:
      • count: Number of colors to generate.
      • format: Color format (hex, rgb, hsl).
    • Returns: An array of random colors.

5. Distributions Utilities

RandomDistributions

  • gaussian(mean: number = 0, stdDev: number = 1): number
    • Generates a random number following a Gaussian distribution.
    • Parameters:
      • mean: Mean of the distribution.
      • stdDev: Standard deviation of the distribution.
    • Returns: A random number.

Installation

npm install random-library

Usage

import { RandomUtils } from "random-library";

// Example: Generate a random UUID
const uuid = RandomUtils.format.uuid();
console.log(uuid);