瀏覽代碼

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()));
     }