欢迎使用CSDN-markdown编辑器

来源:互联网 发布:ubuntu 重装ssh 编辑:程序博客网 时间:2024/06/04 20:10
/* * author:wsx */public List<TSDepart> getSubStringByRadom(List<TSDepart> list, int count){    List backList = null;    backList = new ArrayList<TSDepart>();    Random random = new Random();    int backSum = 0;    if (list.size() >= count) {        backSum = count;    }else {        backSum = list.size();    }    for (int i = 0; i < backSum; i++) {

// 随机数的范围为0-list.size()-1
int target = random.nextInt(list.size());
backList.add(list.get(target));
list.remove(target);
}
return backList;
}