generating a random number in javascript code example
Example 1: random int between two numbers javascript
Math.floor(Math.random() * (max - min + 1)) + min;
Math.floor(Math.random() * (max + 1));
Math.floor(Math.random() * max) + 1;
Example 2: random number javascript
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
console.log(getRandomInt(3));
console.log(getRandomInt(1));
console.log(Math.random());
Example 3: javascript random number between
Math.floor(Math.random() * 6) + 1
Example 4: javascript generate random number
Math.random();
Example 5: how to generate a random number in javascript
var min = 5;
var max = 25;
var rdm = (Math.random() * (max - min)) + min
var rdm = Math.round((Math.random() * (max - min)) + min)