generate random int javascript 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: generate random number javascript
function randomNumber(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
}
Example 3: angular random number between 1 and 10
function randomNumber(min, max) {
return Math.random() * (max - min) + min;
}
Example 4: javascript random
function random(min, max) {
return ~~(Math.random() * (max - min + 1) + min);
}
random(1, 5);
Example 5: generate random integer javascript
function getRandomArbitrary(min, max) {
return Math.random() * (max - min) + min;
}
function getRandomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}