Generates a random integer between the specified min and max values, inclusive.
Ensures the result is within the whole number range using Math.ceil and Math.floor.
Parameters
min: number
The minimum integer value (inclusive).
max: number
The maximum integer value (inclusive).
Returns number
A random integer between min and max, inclusive.
Example
constroll = genRandomInRange(1, 6); console.log(`You rolled a ${roll}`); // Output: You rolled a 3 (or any number between 1 and 6)
Example
consttemperature = genRandomInRange(-10, 40); console.log(`Temperature: ${temperature}°C`); // Output: Temperature: 22°C (or any between -10 and 40)
Generates a random integer between the specified
minandmaxvalues, inclusive. Ensures the result is within the whole number range usingMath.ceilandMath.floor.