© xkcd.com
Randomness algorithms for JavaScript. See docs. Parent is js-algorithms.
⚠️ Depending on your environment, the code may requireregeneratorRuntimeto be defined, for instance by importing regenerator-runtime/runtime.
import{randint,// randint(i, j) => [i, j[ \cap ZZrandfloat,// randfloat(i, j) => [i, j[sample,// sample(k, array, i, j) /!\ in-place (output is items i through i + k - 1)shuffle,// shuffle(array, i, j) /!\ in-placereservoirassampled,// sampled(k, iterable[, output = []]) => sample arrayshuffled,// shuffled(iterable[, output = []]) => shuffled arraychoice,// choice(array, i, j) => itemrandrange,// randrange([start = 0,] stop[, step = 1]) => item}from'@randomized/random';// NOTE a specific entropy source can be used by constructing these functions// from their low-level implementation, for instanceimport{_fisheryates,_randint}from'@randomized/random';import{splitmix64,nextFloat64}from'@entropy-source/pseudo-random';constprng=splitmix64([123,456]);constrandom=()=>nextFloat64(prng);constrandint=_randint(random);constsample=_fisheryates(randint);