/**
* 用户输入机选注数
*/
public static int getNumber(){
//指定生成注数
boolean bl = false;
String zhushu = "";
do
{
S
canner input = new Scanner(System.in);
System.out.println("请输入机选注数:");
zhushu = input.next();
String reg = "[1-9][0-9]+";
Pattern p = Pattern.compile(reg);
Matcher m = p.matcher(zhushu);
if(m.matches())
bl = true;
else
bl = false;
}while(!bl);
return Integer.parseInt(zhushu);
}
/**
* 随机生成N注双色球号码
* @param args
*/
public static List<StringBuffer> bulidRandomNum(int zhushu)
{
List<StringBuffer> randomNumber = new ArrayList<StringBuffer>();//生成的指定的注数的号码
Random random = new Random();
for (int i = 0; i < zhushu; i++)
{
StringBuffer sb = new StringBuffer();
boolean [] bl_red = new boolean[34];
boolean [] bl_blue = new boolean[17];
int red = 0; //红球
int blue = 0; //蓝球
for (int j = 0; j < 6; j++) {
do
{
red = random.nextInt(33)+1;//随机范围为[0,33)所以这里要加1
}while(bl_red[red]);
bl_red[red] = true;
sb.append(red);
if (j!=5) {
sb.append(",");
}
}
blue = random.nextInt(16)+1;
sb.append("+" + blue);
randomNumber.add(sb);
}
return randomNumber;
}
public static void main(String[] args)
{
int zhushu = getNumber();
List<StringBuffer> list = bulidRandomNum(zhushu);
for (int i = 0; i < list.size(); i++)
{
System.out.println(list.get(i)+"\n");
}
}
//以上纯属消遣,有不足之处,忘指点。