java生成10个不相等的1-20的随机数

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

转载于:https://www.cnblogs.com/Mr-nie/p/11107855.html

你可能感兴趣的:(java生成10个不相等的1-20的随机数)