getRandomInt
getRandomInt
Generates a random integer between a specified minimum and maximum value.
Parameters:
min
(number): The minimum value.max
(number): The maximum value.
Returns:
(number): A random integer between
min
andmax
inclusive.
Example Usage:
// Example 1: Basic usage
console.log(getRandomInt(1, 10)); // might output 3
// Example 2: Specifying a negative range
console.log(getRandomInt(-5, 5)); // might output -2
// Example 3: Minimum and maximum are the same
console.log(getRandomInt(7, 7)); // will always output 7
This function is useful for scenarios where you need a random integer within a specific range, making it ideal for tasks such as randomizing selections, simulations, or games.
Last updated