generate random whole numbers within a range code example
Example 1: Generate random whole numbers within a range javascript
function randomRange(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
console.log(randomRange(1,9));
Example 2: generate random whole numbers within a range
var myMin = 1;
var myMax = 10;
function randomRange(myMin, myMax) {
return Math.floor(Math.random() * (myMax - myMin + 1)) + myMin;
}
console.log(randomRange(myMin, myMax));