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

@thi.ng/random

v4.1.35

Published

Pseudo-random number generators w/ unified API, distributions, weighted choices, ID generation

Downloads

961,266

Readme

@thi.ng/random

npm version npm downloads Mastodon Follow

[!NOTE] This is one of 211 standalone projects, maintained as part of the @thi.ng/umbrella monorepo and anti-framework.

🚀 Please help me to work full-time on these projects by sponsoring me on GitHub. Thank you! ❤️

About

Pseudo-random number generators w/ unified API, distributions, weighted choices, ID generation.

[!IMPORTANT] In July 2024 this package was restructured and split-up to extract some features into smaller more focused packages:

This package provides the IRandom interface and various (mostly seedable) pseudo-random number generator implementations, incl. IRandom wrappers for Math.random() (or other external PRNGs) and window.crypto:

Partially ported from C implementations taken from c.thi.ng.

Random distributions

Other utilities

Status

STABLE - used in production

Search or submit any issues for this package

Support packages

Related packages

  • @thi.ng/ksuid - Configurable K-sortable unique IDs, ULIDs, binary & base-N encoded, 32/48/64bit time resolutions

Installation

yarn add @thi.ng/random

ESM import:

import * as rnd from "@thi.ng/random";

Browser ESM import:

<script type="module" src="https://esm.run/@thi.ng/random"></script>

JSDelivr documentation

For Node.js REPL:

const rnd = await import("@thi.ng/random");

Package sizes (brotli'd, pre-treeshake): ESM: 1.93 KB

Dependencies

Note: @thi.ng/api is in most cases a type-only import (not used at runtime)

Usage examples

19 projects in this repo's /examples directory are using this package:

| Screenshot | Description | Live demo | Source | |:-----------------------------------------------------------------------------------------------------------------------------|:-----------------------------------------------------------------------------------------|:------------------------------------------------------------|:-----------------------------------------------------------------------------------------| | | Self-modifying, animated typographic grid with emergent complex patterns | Demo | Source | | | Probabilistic color theme generator | Demo | Source | | | Interactive inverse FFT toy synth | Demo | Source | | | 2D Bezier curve-guided particle system | Demo | Source | | | Basic hiccup-based canvas drawing | Demo | Source | | | Barnsley fern IFS fractal renderer | Demo | Source | | | k-means clustering visualization | Demo | Source | | | Randomized space-filling, nested grid layout generator | Demo | Source | | | Randomized 4-point 2D color gradient image generator | Demo | Source | | | Interactive pixel sorting tool using thi.ng/color & thi.ng/pixel | Demo | Source | | | Animated, iterative polygon subdivisions & visualization | Demo | Source | | | Procedural stochastic text generation via custom DSL, parse grammar & AST transformation | Demo | Source | | | Basic usage of thi.ng/rdom keyed list component wrapper | Demo | Source | | | Generative audio synth offline renderer and WAV file export | Demo | Source | | | Evolutionary shader generation using genetic programming | Demo | Source | | | Responsive & reactively computed stacked column layout | Demo | Source | | | thi.ng/rdom & thi.ng/rstream based quiz to guess thi.ng package names | Demo | Source | | | Animated t-SNE visualization of 4D data | Demo | Source | | | Game of Life implemented as WebGL2 multi-pass shader pipeline | Demo | Source |

API

Generated API docs

import { Smush32 } from "@thi.ng/random";

const rnd = new Smush32(0xdecafbad);

// the following methods are available for all generators

// next uint (0 .. 2^32-1)
rnd.int()
// 4022849029

// next float [0.0 .. 1.0)
rnd.float()
// 0.2698542904737066

// next normalized float (w/ opt scale)
// [-scale .. +scale)
rnd.norm(100)
// 57.70723665079737

// next float in given interval [min .. max)
rnd.minmax(10, 20)
// 15.295951807707537

rnd.minmaxInt(10, 20)

Authors

If this project contributes to an academic publication, please cite it as:

@misc{thing-random,
  title = "@thi.ng/random",
  author = "Karsten Schmidt",
  note = "https://thi.ng/random",
  year = 2015
}

License

© 2015 - 2025 Karsten Schmidt // Apache License 2.0