当前位置 : 主页 > 编程语言 > c++ >

从一个List中随机取出特定数字的记录

来源:互联网 收集:自由互联 发布时间:2021-07-03
根据指定的List和取出数得到子List public List getSubStringByRadom(List list, int count){ List backList = null; backList = new ArrayList (); Random random = new Random(); int backSum = 0; if (list.size() = count) { backSum = count
根据指定的List和取出数得到子List
public List
 
   getSubStringByRadom(List
  
    list, int count){ List backList = null; backList = new ArrayList
   
    (); 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; }
   
  
 
网友评论