ixfx
    Preparing search index...

    Module @ixfx/random - v0.44.0

    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

    Functions

    bipolar

    Returns a random bipolar value

    bipolarSource

    Source for random bipolar values

    calculateNonZero

    Keeps generating a random number until it's not 0

    chance

    Chance of returning a or b, based on threshold p.

    float

    Returns a random float between max (exclusive) and 0 (inclusive).

    floatSource

    Returns a function that produces random float values. Use float to produce a valued directly.

    gaussian

    Returns a random number with gaussian (ie. bell-curved) distribution

    gaussianSource

    Returns a function that generates a gaussian-distributed random number

    integer

    Returns a random integer between max (exclusive) and 0 (inclusive) Use integerSource to return a function instead.

    integerSource

    Returns a function that produces a random integer between max (exclusive) and 0 (inclusive) Use integer if you want a random number directly.

    integerUniqueGen

    Returns a generator over random unique integers, up to but not including the given max value.

    mersenneTwister

    Reproducible random values using the Merseene Twister algorithm. With the same seed value, it produces the same series of random values.

    minutesMs

    Returns a random number of minutes, with a unit of milliseconds.

    minutesMsSource

    Returns a random number of minutes, with a unit of milliseconds.

    randomElement

    Returns random element.

    randomElementWeightedSource

    Selects a random array index, biased by the provided weightings.

    randomIndex

    Returns a random array index.

    randomPluck

    Plucks a random value from an array, optionally mutating the original array.

    secondsMs

    Returns function which produces a random number of seconds, with a unit of milliseconds.

    secondsMsSource

    Returns function which produces a random number of seconds, with a unit of milliseconds.

    shortGuid

    Generates a six-digit roughly unique id

    shuffle

    Returns a shuffled copy of the input array.

    string

    Returns a string of random letters and numbers of a given length.

    weighted

    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.

    weightedIndex

    Returns a random number from 0..weightings.length, distributed by the weighting values.

    weightedInteger

    Generate a weighted-random integer.

    weightedIntegerSource

    Random integer, weighted according to an easing function. Number will be inclusive of min and below max.

    weightedSource

    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.

    Type Aliases

    GenerateRandomOptions
    RandomBooleanOptions

    Options for generating a random boolean

    RandomNumberOptions
    RandomOptions
    RandomSource

    A random source.

    StringOptions
    WeightedOptions