Skip to main content
@spa-tools/utilities

getRandomNumber()

The getRandomNumber() function returns a random number between provided min (inclusive) and max (exclusive by default).

Usage

import { getRandomNumber } from '@spa-tools/utilities';

// random number between 1 and 10, excluding 10
const randomNumber1 = getRandomNumber(1, 10);

// random number between 1 and 10, including both 1 and 10
const randomNumber2 = getRandomNumber(1, 10, true);

Arguments

NameTypeDescription
minnumberThe lower range of random number (inclusive)
maxnumberThe upper range of randome number (exclusive by default)
includeMaxbooleanWhether to include max in the random number

Returns

Returns the randomly generated number.