javascript random value code example
Example 1: js random number
var random;
var max = 8
function findRandom() {
random = Math.floor(Math.random() * max)
console.log(random)
}
findRandom()
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 random number in range
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min)) + min;
}
Example 4: how to generate a random number in javascript
var min = 5;
var max = 25;
var rdm = (Math.random() * (max - min)) + min
var rdm = Math.round((Math.random() * (max - min)) + min)
Example 5: random number in javascript
var randomNo = Math.floor(Math.rand() * 10000000001);
console.log(randomNo);