随机返回list对象
/**
* 返回随机List
* @param list 备选
* @param selected 备选数量
* @return
*/
public List getRandomNum(List list, int selected) {
List<Object> reList = new ArrayList<Object>(); Random random = new Random();
// 先抽取,备选数量的个数
if (list.size() >= selected) {
for (int i = 0; i < selected; i++) {
// 随机数的范围为0-list.size()-1;
int target = random.nextInt(list.size());
reList.add(list.get(target));
list.remove(target);
}
} else {
selected = list.size();
for (int i = 0; i < selected; i++) {
// 随机数的范围为0-list.size()-1;
int target = random.nextInt(list.size());
reList.add(list.get(target));
list.remove(target);
}
} return reList;
}