[!NOTE]
This is one of 192 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.
This package provides the IRandom
interface and various (mostly seedable)
pseudo-random number generator implementations, incl. IRandom
wrappers for
Math.random()
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://cdn.skypack.dev/@thi.ng/random"></script>
Skypack documentation
For Node.js REPL:
const rnd = await import("@thi.ng/random");
Package sizes (brotli'd, pre-treeshake): ESM: 2.02 KB
Dependencies
Usage examples
Several 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 |
| 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 |
| 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);
rnd.int()
rnd.float()
rnd.norm(100)
rnd.minmax(10, 20)
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 - 2024 Karsten Schmidt // Apache License 2.0