rand number 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 random number between 1 and 10
Math.random();
var theRandomNumber = Math.floor(Math.random() * 10) + 1;
Example 3: get random numbers javascript
Math.floor(Math.random() * n);
Example 4: generate number using math random in javascript
console.log(Math.round(Math.random() * 10))
Example 5: random number in js
Math.random() returns a random number in [0,1)