js generates random numbers from 1 to 100
js generates random numbers using the math.random() function
Math.random()
Specific implementation:
1. Define a random() function. The principle is to multiply the random number by the difference between the maximum value minus the minimum value and finally add the minimum value.
function random(min, max) { return Math.floor(Math.random() * (max - min)) + min; }
2. How to use
for (var i = 1; i <= 10; i++) { console.log(random(1, 100)); }
3. Rendering
##This article comes from thejs tutorial column, welcome study!
The above is the detailed content of js generates random numbers from 1 to 100. For more information, please follow other related articles on the PHP Chinese website!