随机列表

  1. import cn.hutool.core.util.RandomUtil;
  2. public List<Long> getRandomIds(List<Long> mchIds) {
  3. // 随机之前
  4. List<Long> beforeList = Arrays.asList(1L,2L,3L,4L);
  5. // 随机之后
  6. List<Long> randomList = new ArrayList<>();
  7. while (beforeList.size() > 0) {
  8. int randomNum = RandomUtil.randomInt(beforeList.size());
  9. randomList.add(beforeList.get(randomNum));
  10. beforeList.remove(randomNum);
  11. }
  12. return randomList;
  13. }