java生成10个不相等的1-20的随机数
public class Test {
public static void main(String[] args){
Random ran = new Random();
Set <Integer> set = new HashSet<Integer>();
while(set.size()==10?false:true){
int num = ran.nextInt(20)+1;
set.add(num);
}
Iterator<Integer> it = set.iterator();
int count = 0;
while(it.hasNext()){
System.out.println("第"+ ++count +"个随机数 =="+it.next());
}
}
}