第1个回答 2016-05-24
package com.args;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
public class RandomTest {
public static void main(String[] args) {
int[] arr = new int[33];
Random random = new Random();
Set<Integer> set = new HashSet<>();
int length = 6;
int count = 0;
for (int i = 0; i < arr.length; i++) {
set.add(random.nextInt(1 + arr.length));
count++;
if (set.size() == length) {
break;
}
}
System.out.println(String.format("%s;\n循环次数%s", set, count));
}
}本回答被网友采纳