Package Exports
- @thi.ng/random
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@thi.ng/random) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
This project is part of the @thi.ng/umbrella monorepo.
About
Pseudo-random number generators w/ unified API.
This package provides the IRandom
interface and various (mostly
seedable) pseudo-random number generator implementations, incl. a
IRandom
wrapper for Math.random()
:
Partially ported from C implementations taken from c.thi.ng.
Status
STABLE - used in production
Search or submit any issues for this package
Installation
yarn add @thi.ng/random
// ES module
<script type="module" src="https://unpkg.com/@thi.ng/random?module" crossorigin></script>
// UMD
<script src="https://unpkg.com/@thi.ng/random/lib/index.umd.js" crossorigin></script>
Package sizes (gzipped, pre-treeshake): ESM: 1.51 KB / CJS: 1.62 KB / UMD: 1.63 KB
Dependencies
Usage examples
Several demos in this repo's /examples directory are using this package.
A selection:
Screenshot | Description | Live demo | Source |
---|---|---|---|
![]() |
Interactive inverse FFT toy synth | Demo | Source |
![]() |
Evolutionary shader generation using genetic programming | Demo | Source |
API
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
// next gaussian (using iterative CLT approach)
// optional params: num samples, offset, scale
rnd.gaussian()
// 0.10632886109089679
Other utilities
Authors
Karsten Schmidt
License
© 2016 - 2020 Karsten Schmidt // Apache Software License 2.0