/**
* lowerValue 最小值
* upperValue 最大值
*/
function selectFrom(lowerValue, upperValue){
//取值范围总数
var choices = upperValue - lowerValue + 1;
return Math.floor(Math.random() * choices + lowerValue);
}
var num = selectFrom(2, 10);
alert(num);//介于2和10之间(包括2和10)的一个数值
var colors = ["red","green","blue","yellow","black","brown"];
var color = colors[selectFrom(0, colors.length-1)];
alert(color);//可能是数组中包含的任何一个值