0
How to make random number on JS?
2 Answers
+ 4
The Math object has a random() method that returns a random value between 0 and 1, you can call it like "Math.random()".
Based on that method, you can make your own random function, for example:
function rand(min, max) {
return Math.floor( Math.random() * (max - min + 1) ) + min;
}
+ 1
Math.floor(Math.random() * 10)
returns a random number either 1,2,3,4,5,6,7,8 or 9