以[10,20)区间随机产生10个整数为例展示:
//list :有序 可重复
public static void fun1(){
List<Integer> list = new ArrayList<Integer>();
do{
int a = (int) (Math.random()*10+10);
if(!list.contains(a)){
list.add(a);
}
}while(list.size() <10);
System.out.println(list);
}
//set无序 不可重复
public static void fun3(){
Set<Integer> set1 = new HashSet<>();
do{
int a = (int) (Math.random()*10+10);
set1.add(a);
}while(set1.size()<10);
System.out.println(set1);
}
总:list可重复,所以数据