randomnumber javascript 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 get random number in range
function getRandomNumberBetween(min,max){
return Math.floor(Math.random()*(max-min+1)+min);
}
Example 3: generate random number javascript
function randomNumber(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
Example 4: get random numbers javascript
Math.floor(Math.random() * n);
Example 5: random int javascript
Math.floor(Math.random()*3)
Example 6: how to write a program that shows a random number between 1 and 100 in your browser
var randomNum ;
randomNum = Math.ceil(Math.random() * 100);
document.write("Random number between 1 and 100: " + randomNum)