@cto.af/random
v2.1.1
Published
Description
Readme
@cto.af/random
Description
Installation
npm install @cto.af/randomAPI
Full API documentation is available.
Example:
import {Random} from '@cto.af/random';
const r = new Random();
r.upTo(10); // 0-9
r.pick(['a', 'b', 'c']); // One of those strings.
r.some(['a', 'b', 'c']); // 0-3 of those strings.
r.gauss(1.0, 0.2); // Normal distribution around 1.0 with a stdDev of 0.2.There is also a test harness available, that allows you to pre-load a random instance so that it generates predictable results:
import {Modnar} from '@cto.af/random/test';
import {Random} from '@cto.af/random';
const m = new Modnar();
const r = new Random(m.source);
m.uInt32(1);
m.uBigInt(1234567890n);
r.uInt32(); // 1
r.uBigInt(); // 1234567890n