npm

Ready to take your JavaScript development to the next level? Meet npm Enterprise - the ultimate in enterprise JavaScript.Learn more »

@thi.ng/random

1.1.7 • Public • Published

@thi.ng/random

npm (scoped) npm downloads Twitter Follow

This project is part of the @thi.ng/umbrella monorepo.

About

This package provides the IRandom interface and various (mostly seedable) pseudo-random number generator implementations, incl. a IRandom wrapper for Math.random():

Installation

yarn add @thi.ng/random

Dependencies

Usage examples

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

Authors

  • Karsten Schmidt

License

© 2018 Karsten Schmidt // Apache Software License 2.0

install

npm i @thi.ng/random

Downloadsweekly downloads

828

version

1.1.7

license

Apache-2.0

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability