random方法可返回介于 0(包含)~1(不包含)之间的一个随机数
Math.random()
实例1:
取得介于1到10之间的一个随机数
Math.floor((Math.random()*10)+1);
实例2:
取得介于1到100之间的一个随机数
Math.floor((Math.random()*100)+1);
实例3:
以下函数返回min(包含)~ max(不包含)之间的数字:
function getRndInteger(min,max) {
return Math.floor(Math.random() * (max-min))+min;
}
实例4:
以下函数返回min(包含)~ max(包含)之间的数字:
function getRndInteger(min,max) {
return Math.floor(Math.random() * (max-min+1))+min;
}