天天看點

javascript擷取随機數的幾種方式

//擷取0-num的随機數
		function randomNum(num){
			return Math.floor(Math.random()*num);
		}
		
		//擷取start-end的随機數
		function randomNum1(start,end){
			return Math.floor(Math.random()*(end - start +1) + start);
		}
		
		//擷取start-end的随機數
		function randomNum2(start,end){
			return Math.ceil(Math.random()*(end - start+1) + start-1);
		}
           

  

轉載于:https://www.cnblogs.com/sun-rain/p/4806723.html

繼續閱讀