what does math.random do 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: random number javascript
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
console.log(getRandomInt(3));
console.log(getRandomInt(1));
console.log(Math.random());
Example 3: javascript get random integer in given range
const randomInteger = (min, max) => Math.floor(Math.random() * (max - min + 1)) + min;
Example 4: random numbers javascript
Math.floor(Math.random() * 100);
random integer from 0 to 99
Example 5: math.random
int random = (int) (Math.random()*(max-min+1)+min);
Example 6: math random js
function getRandomIntInclusive(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}