rand in 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: js random number
var random;
var max = 8
function findRandom() {
random = Math.floor(Math.random() * max)
console.log(random)
}
findRandom()
Example 3: random int javascript
Math.floor(Math.random()*3)
Example 4: javascript random
function random(min, max) {
return ~~(Math.random() * (max - min + 1) + min);
}
random(1, 5);