随机整数函数

function randomNum(minNum,maxNum){
  var choices = maxNum - minNum + 1;
  return Math.floor(Math.random() * choices + minNum);
}

var num = randomNum(2, 10);
alert(num);   //2-10的随机数(包括2或10);

原文地址:https://www.cnblogs.com/rongy/p/6613436.html