javascript random number between 0 and 4 code example
Example 1: math.random javascript
Math.random()
Math.floor(Math.random() * 10)
Math.floor(Math.random() * 11)
function randomNum(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
Example 2: javascript random number between 1 and 10
Math.random();
var theRandomNumber = Math.floor(Math.random() * 10) + 1;
Example 3: javascript generate a random integer number in a range of numbers
const min = 1;
const max = 4;
const intNumber = Math.floor(Math.random() * (max - min)) + min;
console.log(intNumber);
Example 4: get random numbers javascript
Math.floor(Math.random() * n);
Example 5: javascript random number 1 or -1
var number = ((Math.floor(Math.random() * 2) - 2) * 2) + 1