Skip to content

Random

Helpers for working with randomness, various functions for random numbers and other values.

randomNumber

Function (min: number, max: number) => number

Returns a random number between the provided min (minimum) and max (maximum) values.

Number may include a decimal value, use randomInteger to only get whole numbers

ArgumentTypeExampleDescription
minnumber5.5The minimum possible number allowed
maxnumber50The maximum possible number allowed
const value = api.random.randomNumber(5.5 /* min */, 50 /* max */);
console.log(value) // 5.5 - 50

randomInteger

Function (min: number, max: number) => number

Returns a random number between the provided min (minimum) and max (maximum) values.

ArgumentTypeExampleDescription
minnumber5The minimum possible number allowed
maxnumber50The maximum possible number allowed
const value = api.random.randomInteger(5 /* min */, 50 /* max */);
console.log(value) // 5 - 50

randomBoolean

Function () => boolean

Randomly returns either true or false

const value = api.random.randomBoolean();
console.log(value) // true / false

randomArrayItem

Function <T>(array: T[]) => T

Picks a random item from the provided array

ArgumentTypeExampleDescription
arrayarray[ "test", "test2", "test3"]The list of values to pick from
const items = [
"test",
"test2",
"test3"
];
const value = api.random.randomArrayItem(items);
console.log(value) // test / test2 / test3