Skip to content

Latest commit

 

History

History
99 lines (67 loc) · 3.38 KB

tpl.readme.md

File metadata and controls

99 lines (67 loc) · 3.38 KB

About

{{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.

Random distributions

Other utilities

{{meta.status}}

{{repo.supportPackages}}

{{repo.relatedPackages}}

{{meta.blogPosts}}

Installation

{{pkg.install}}

{{pkg.size}}

Dependencies

{{pkg.deps}}

{{repo.examples}}

API

{{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)