javascript求最大最小随机数
1. 第一种
1 random:function(min,max){ 2 var min,max; 3 return Math.floor(Math.random()*max+min); 4 }
2.第二种
1 random:function(min,max){ 2 //取值范围总数 3 var choices = max- min+ 1; 4 return Math.floor(Math.random() * choices + min); 5 }
两种方法都有效,个人感觉第二种更好用一点。

浙公网安备 33010602011771号