Functions for generating random values.
It has a notion of a 'random source', a function that produces a scalar on 0..1 range. If not specified, Math.random
is used throughout these functions. But it allows you to slot in a different number generator.
There are narrowed random generators to produce integers, booleans, time values and so on. These will have a '..Source' version, eg integer
and integerSource
. The simple version returns the random value directly. This is useful if there's only one place where you're creating the value. However, if you're creating the random value at various places, it might be desired to 'bake in' the parameters. the 'Source' alternate returns a function which is callable to produce a value on demand.
For example:
const v1 = integer({ max: 5, min: 10 }); // Random integer value
const f = integerSource({ max: 5, min: 10 }); // Function which produces integer value
const v2 = f(); // Generate the value
Source for random bipolar values
Keeps generating a random number until it's not 0
Chance of returning a
or b
, based on threshold p
.
Returns a random float between max
(exclusive) and 0 (inclusive).
Returns a function that produces random float values. Use float to produce a valued directly.
Returns a random number with gaussian (ie. bell-curved) distribution
Returns a function that generates a gaussian-distributed random number
Returns a random integer between max
(exclusive) and 0 (inclusive)
Use integerSource to return a function instead.
Returns a function that produces a random integer between max
(exclusive) and 0 (inclusive)
Use integer if you want a random number directly.
Returns a generator over random unique integers, up to but not including the given max value.
Reproducible random values using the Merseene Twister algorithm. With the same seed value, it produces the same series of random values.
Returns a random number of minutes, with a unit of milliseconds.
Returns a random number of minutes, with a unit of milliseconds.
Returns random element.
Selects a random array index, biased by the provided weightings
.
Returns a random array index.
Plucks a random value from an array, optionally mutating the original array.
Returns function which produces a random number of seconds, with a unit of milliseconds.
Returns function which produces a random number of seconds, with a unit of milliseconds.
Generates a six-digit roughly unique id
Returns a shuffled copy of the input array.
Returns a string of random letters and numbers of a given length
.
Returns a random number, 0..1, weighted by a given easing function. See @ixfx/modulation.weighted to use a named easing function. Use weightedSource to return a function instead.
Returns a random number from 0..weightings.length, distributed by the weighting values.
Generate a weighted-random integer.
Random integer, weighted according to an easing function.
Number will be inclusive of min
and below max
.
Returns a random number, 0..1, weighted by a given easing function. See @ixfx/modulation.weighted to use a named easing function. Use weighted to get a value directly.
Options for generating a random boolean
A random source.
Returns a random bipolar value