@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
Name | Type | Description |
---|---|---|
min | number | The lower range of random number (inclusive) |
max | number | The upper range of randome number (exclusive by default) |
includeMax | boolean | Whether to include max in the random number |
Returns
Returns the randomly generated number.