public class RandomDemo {
public static void main(String args[]){
int scoreNumber = 1000;
int zero =0, one = 1,two = 2, three = 3,four = 4,five =5;
int zeroTag =0,oneTag =0,twoTag =0,threeTag =0,fourTag =0,fiveTag =0;
Double zeroProportion,oneProportion,twoProportion,threeProportion,fourProportion,fiveProportion;
for(int i = 0;i<scoreNumber;i++){
Random r = new Random();
int number = r.nextInt(6);
if(number==zero){
zeroTag++;
}else if(number==one){
oneTag++;
}else if(number==two){
twoTag++;
}else if(number==three){
threeTag++;
}else if(number==four){
fourTag++;
}else if(number==five){
fiveTag++;
}else{
System.out.println("随机数生成异常");
}
}
zeroProportion = 1.0*zeroTag/scoreNumber;
oneProportion = 1.0*oneTag/scoreNumber;
twoProportion = 1.0*twoTag/scoreNumber;
threeProportion = 1.0*threeTag/scoreNumber;
fourProportion = 1.0*fourTag/scoreNumber;
fiveProportion = 1.0*fiveTag/scoreNumber;
Double total = zeroProportion+oneProportion+twoProportion+threeProportion+fourProportion+fiveProportion;
System.out.println("zeroProportion="+zeroProportion+","+"oneProportion="+oneProportion+","+"twoProportion="+twoProportion+","+"threeProportion="+threeProportion+","+"fourProportion="+fourProportion+","+"fiveProportion="+fiveProportion);
System.out.println("total="+total);
}
}