@huth/random
v4.0.0
Published
Simple utility wrapper for generating randomness.
Readme
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 floatinteger(min: number, max: number): number
inclusive random integerboolean(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 providednoise(x, y?, z?): number
simplex noise in the range[0, 1]
(seeded with a fixed value)id(): string
generates an id alacjld2cjxh0000qzrmn831i7rn