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);