소스 검색

more random seed

Mr.qian 2 주 전
부모
커밋
c1358c9a25
1개의 변경된 파일3개의 추가작업 그리고 3개의 파일을 삭제
  1. 3 3
      mall-service/src/main/java/com/txz/mall/util/RandomUtil.java

+ 3 - 3
mall-service/src/main/java/com/txz/mall/util/RandomUtil.java

@@ -20,10 +20,10 @@ public class RandomUtil {
             return Collections.emptyList();
         }
         
-        // 创建副本以避免修改原始列表
         List<T> copyList = new ArrayList<>(originalList);
-        // 打乱顺序
-        Collections.shuffle(copyList);
+        Random random = new Random();
+        random.setSeed(System.nanoTime() + random.nextLong());
+        Collections.shuffle(copyList, random);
         // 取出前 count 个
         return copyList.subList(0, Math.min(count, copyList.size()));
     }