javascript random numver from 1 to 9 code example
Example 1: Math.random() javascript
console.log(Math.random());
function getRandomBetween(min, max) {
return Math.random() * (max - min) + min;
}
console.log(getRandomBetween(20,170));
function getRandomIntBetween(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
console.log(getRandomIntInclusive(0,25));
Example 2: random number in js
Math.floor(Math.random() * 5)
# it will give whole random number upto 5.
# you can add your lastIndex at place of (5).
# Math.floor() function returns the largest integer less than or equal to a given number.