package javatest;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
public class ball {
Random r = new Random();
public Set getRed() {
Set redSet = new HashSet();
for (int i = 0; i < 100; i++) {
if (redSet.add((int) r.nextInt(32) + 1)) {
if (redSet.size() == 6) {
break;
}
} else {
continue;
}
}
return redSet;
}
public int getBlue() {
int blue = r.nextInt(11) + 1;
return blue;
}
public static void main(String[] args) {
for (int j = 0; j < 5; j++) {
ball b = new ball();
Set redSet = b.getRed();
int blue = b.getBlue();
System.out.println("兰球号码是:" + redSet + ",红球号码是:" + blue);
}
}
}
双色球随机算法
最新推荐文章于 2022-07-09 16:04:24 发布