package randomdemo;
import java.util.Arrays;
import java.util.Random;
/*
* 随机数实现双色球demo
*/
public class RandomDemo {
public static void main(String[] args) {
//球池
int[] ballpool = new int[33];
for(int i=0; i< ballpool.length ; i++){
ballpool[i] = i+1;
}
//创建红球奖池
int[] redResult = new int[6];
int length = 0;
//标记池,默认为false
boolean[] isUsed = new boolean[33];
Random rd = new Random();
//生成红球奖池
while(true){
int red = rd.nextInt(33);
//去重
if(isUsed[red]==true){
continue;
}
//将选中的红球放入结果中,然后数组长度自增
redResult[length++] = ballpool[red];
//循环出口
if(length == 6) break;
//去重
isUsed[red] = true;
}
//将数组排序
Arrays.sort(redResult);
//篮球奖池
int blueResult = rd.nextInt(16);
System.out.println("红球奖池:");
for(int i : redResult){
System.out.print(i+" ");
}
System.out.println("\n蓝球奖池: \n"+blueResult);
}
}