Java 二维数组双色球随机数生成与频率统计
功能说明
本文演示如何使用 Java 二维数组处理双色球号码生成与筛选。规则设定为红球 1-32 选 5 个,蓝球 1-16 选 2 个。目标是通过随机生成多组号码,统计数字出现频率,并筛选出重合率最低的组合。
核心逻辑
1. 随机生成器
使用二维数组存储生成的号码。通过 Random 类生成随机数,并利用辅助方法确保每行内无重复数字。
public static int[][] generator(int a, int b) {
int[][] arr = new int[a][b];
Random random = new Random();
int c = 0;
for (int i = 0; i < arr.length; i++) {
for (int j = 0; j < arr[i].length; j++) {
while (true) {
c = j == 5 || j == 6 ? random.nextInt(15) + 1 : random.nextInt(31) + 1;
if (!contains(c, arr[i])) {
break;
}
}
arr[i][j] = c;
}
}
return arr;
}
public static boolean contains( a, [] sss) {
;
( er : sss) {
result = er == a ? : ;
(result) {
;
}
}
result;
}

