/**
* @Author zhouaokai
* @Description 在list中获取num个不重复的的随机数
* @Date 11:51 2020/5/26
*/
public static <E> List<E> listRandomForParam(List<E> list, int num){
List<E> listResult = new ArrayList<>();
if (list != null && list.size() > 0 && num > 0){
//随机取出num条不重复的数据
for (int i = num; i > 0; i--) {
Random random = new Random();
//在数组大小之间产生一个随机数 j
int j = random.nextInt(list.size()-1);
//取得list 中下标为j 的数据存储到 listRandom 中
listResult.add(list.get(j));
//把已取到的数据移除,避免下次再次取到出现重复
list.remove(j);
}
}
return listResult;
}