Random
This is a simple wrapper that provides utilities for dealing with randomness. This library generally uses Math.random
as its random number generator. If you need a deterministic, mathematically correct random number generator, consider random-js
instead. Noise uses simplex-noise
and alea
, and ids cuid
.
npm install @huth/random
Default export contains all available methods:
import random from "@huth/random"
random.pick("Rose", "Blanche", "Dorothy", "Sophia") // "Dorothy" 😬
API
The API includes the following methods for producing usefull random data:
-
float(min: number, max: number): number
inclusive random float -
integer(min: number, max: number): number
inclusive random integer -
boolean(likelihood = .5): boolean
boolean wherelikelihood
is a number in the range [0, 1] increasing the chance oftrue
-
pick(...args): any
returns a random element from the arguments provided -
noise(x, y?, z?): number
simplex noise in the range[0, 1]
(seeded with a fixed value) -
id(): string
generates an id alacjld2cjxh0000qzrmn831i7rn