Math.random() 方法可返回介于 0 ~ 1 之间的一个随机数[0.0~1.0)
NumberObject.toFixed(num)方法可把 NumberObject四舍五入为指定小数位数的数字。num取值范围[0~20]
//min 最小值 max 最大值 degs(大于等于0) 保留小数位数(随机产生一个整数位[min,max]保留degs位小数的值)
function randomNum(min,max,degs){
var num = Math.random()*(max-min+1);
var res;
if(degs!=0){
res = num.toFixed(degs);//切记toFixed()方法返回的是字符串类型
}else{
res = parseInt(num);
}
return res;
}