random whole number javascript code example
Example 1: javascript get random number in range
function getRandomNumberBetween(min,max){
return Math.floor(Math.random()*(max-min+1)+min);
}
Example 2: javascript get random number
function getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}
Example 3: javascript random number between 0 and 10
Math.floor(Math.random() * 10);
Example 4: Generate random whole numbers javascript
var randomWholeNumber = Math.floor(Math.random() * 20);
function randomWholeNum() {
return Math.floor(Math.random() * 10);
}
console.log(randomWholeNum());
Example 5: random number in js
Math.random() returns a random number in [0,1)