{{pkg.description}}
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.
coin()
/fairCoin()
pickRandom()
/pickRandomKey()
randomBytes()
/randomBytesFrom()
randomID()
weightedRandom()
/weightedRandomKey()
uniqueIndices()
/uniqueValuesFrom()
{{meta.status}}
{{repo.supportPackages}}
{{repo.relatedPackages}}
{{meta.blogPosts}}
{{pkg.install}}
{{pkg.size}}
{{pkg.deps}}
{{repo.examples}}
{{pkg.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)