xxxxxxxxxx
function roundWholeNum(){
return Math.floor(Math.random() * 20);
}
console.log(roundWholeNum());
xxxxxxxxxx
function randomRange(myMin, myMax) {
return Math.floor(Math.random() * (myMax - myMin + 1) + myMin);
}
xxxxxxxxxx
var myMin = 1;
var myMax = 10;
function randomRange(myMin, myMax) {
return Math.floor(Math.random() * (myMax - myMin + 1)) + myMin;
}
console.log(randomRange(myMin, myMax));
xxxxxxxxxx
<script>
// Function to generate random number
function randomNumber(min, max) {
return Math.floor(Math.random() * (max - min) + min);
}
document.write("Random Number between 1 and 100: ")
// Function call
document.write( randomNumber(1, 100) );
</script>