You can use the random() method, which returns a random number between 0 ~ 1.
The specific code is as follows:
//生成最小min到最大max的随机数 function random(min,max){ if(min > max){ var ls = min; min = max; max = ls; } return Math.floor(Math.random() * (max-min+1) ) + min; }
Recommended tutorial:js entry tutorial
The above is the detailed content of js generates random numbers within a certain range. For more information, please follow other related articles on the PHP Chinese website!