import java.util.Calendar;
import java.util.Random;
public class Rand {
private static int[] getBigRandom(int count, int range) {
Random rnd = new Random(Calendar.getInstance().getTimeInMillis()); //不加这个每次运行结果都一样
int[] big = new int[count];
int k = 0 ,f;
for (int i = 0 ; i< count; i++){
f = rnd.nextInt(range);
big[i] = f+1;
}
return big;
}
private static int[] getNumDistributed(int[] big , int range) {
int[] num = new int[range];
for (int i=0; i < big.length; i++){
num[big[i]-1]++;
}
return num;
}
public static void main(String[] args){
int[] Big ;
int[] num ;
int sum = 0;
Big = getBigRandom(10000 , 10);
num = getNumDistributed(Big,10);
for (int i=0; i<10; i++){
sum += num[i];
p((i+1)+": "+num[i]);
}
p("Total: "+sum);
}
private static void p(Object obj) {
System.out.println(obj);
}
}
温馨提示:内容为网友见解,仅供参考