Class: Rand

Rand

new Rand(seed)

Wrapper library for David Bau's seeded random number generator which is a wrapper for the Math.rand() functionality. This library is implemented to fill out the functionality of the random capabilities as well as build on the capabilities existing in the framework currently. This class can be used on a global or local scale.
Name Type Default Description
seed number | string 0 optional The seed to be applied to the local random number generator
See:
Examples
Rand.seedRandom(0);      // Set the global seed
Rand.rand();             // Predictable based off seed
var rng = new Rand(0);   // Set the local rng seed
rng.rand();              // Predictable based off seed

Rand.rand();             // Unpredictable since global seed is not set

Methods

staticRand.rand(){number}

Get a random number from 0 to 1.
Returns:
Type Description
number random number from 0 to 1

staticRand.randHex(){hex}

Get the random hex value of a color represented in the hexidecimal format
Returns:
Type Description
hex

staticRand.randHexColor(){string}

Get a random hex color string represented in "#HEXSTR" format
Returns:
Type Description
string

staticRand.randInt(min, max){number}

Get a random int in a particular range (min and max inclusive)
Name Type Description
min any
max any
Returns:
Type Description
number Random float number from min (inclusive) to max (exclusive)

staticRand.randRange(min, max){number}

Get a random float value in a particular range
Name Type Description
min any
max any
Returns:
Type Description
number Random float number from min (inclusive) to max (exclusive)

staticRand.setSeed(seed)

Set the global seed for the seeded random number generator. After the seed has been set. The random numbers will be predictable and repeatable given the same input seed. If no seed is specified, then a random seed will be assigned to the random number generator using added system entropy.
Name Type Default Description
seed number | string 0 optional The seed to be applied to the global random number generator

staticRand.vector(bbox){Vector}

Get a random vector in a bounding box
Name Type Description
bbox Rectangle The bounding box of the random vector
Returns:
Type Description
Vector A random vector

rand(){number}

Get a random number from 0 to 1.
Returns:
Type Description
number random number from 0 to 1

randHex(){hex}

Get the random hex value of a color represented in the hexidecimal format
Returns:
Type Description
hex

randHexColor(){string}

Get a random hex color string represented in "#HEXSTR" format
Returns:
Type Description
string

randInt(min, max){number}

Get a random int in a particular range (min and max inclusive)
Name Type Description
min any
max any
Returns:
Type Description
number Random float number from min (inclusive) to max (exclusive)

randRange(min, max){number}

Get a random float value in a particular range
Name Type Description
min any
max any
Returns:
Type Description
number Random float number from min (inclusive) to max (exclusive)

setSeed(seed)

Set the seed for the seeded random number generator. After the seed has been set. The random numbers will be predictable and repeatable given the same input seed. If no seed is specified, then a random seed will be assigned to the random number generator using added system entropy.
Name Type Default Description
seed number | string 0 optional The seed to be applied to the RNG
Get a random vector in a bounding box
Name Type Description
bbox Rectangle The bounding box of the random vector
Returns:
Type Description
Vector A random vector