js 生成概率相同的1-4 随机数

 var random1=0;
 var random2=0;
 var random3=0;
 var random4=0;
 var count=10000000;
 var randomNum;
 var myDate = new Date();
  myDate.getTime();
for(var i=0;i randomNum = Math.round((Math.random()*myDate.getTime())%1000000000000)%5
 
if(randomNum==1){
random1++;
}else if(randomNum==2){
random2++;
}else if(randomNum==3){
random3++;
}else if(randomNum==4)
random4++;
}
alert("1出现的概率是:"+Math.round((random1/count)*100)+"
 2出现的概率是:"+Math.round((random2/count)*100)+"  3出现的概率是:"+Math.round((random3/count)*100)+"  4出现的概率是:"+Math.round((random4/count)*100));

你可能感兴趣的:(js)