getRandomNum: function(minNum, maxNum, decimalNum) {
var max = 0, min = 0
minNum <= maxNum ? (min = minNum, max = maxNum) : (min = maxNum, max = minNum)
switch (arguments.length) {
case 1:
return Math.floor(Math.random() * (max + 1))
case 2:
return Math.floor(Math.random() * (max - min + 1) + min)
case 3:
return (Math.random() * (max - min) + min).toFixed(decimalNum)
default:
return Math.random()
}
},
网友评论