List<Integer> list = new ArrayList<>();
for(int i=1;i<=35;i++) {
list.add(i);
}
Collections.shuffle(list);
List<Integer> qian = new ArrayList<>();
for(int i=1;i<=5;i++) {
int index =(int)(Math.random()*(35-i)+0); // [0,35-i]
qian.add(list.remove(index));
Collections.shuffle(list);
}
Collections.sort(qian, new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
return o1-o2;
}
});
System.out.println("前:"+qian);
// 后
List<Integer> list2 = new ArrayList<>();
for(int i=1;i<=12;i++) {
list2.add(i);
}
Collections.shuffle(list2);
List<Integer> hou = new ArrayList<>();
for(int i=1;i<=2;i++) {
int index =(int)(Math.random()*(12-i)+0); // [0,12-i]
hou.add(list2.remove(index));
Collections.shuffle(list2);
}
Collections.sort(hou, new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
return o1-o2;
}
});
System.out.println("后:"+hou);
网友评论