1 //生成从minNum到maxNum的随机数 2 function randomNum(minNum,maxNum){ 3 switch(arguments.length){ 4 case 1: 5 return parseInt(Math.random()*minNum+1,10); 6 break; 7 case 2: 8 return parseInt(Math.random()*(maxNum-minNum+1)+minNum,10); 10 break; 11 default: 12 return 0; 13 break; 14 } 15 }