Browse Source

more random seed

Mr.qian 2 tuần trước cách đây
mục cha
commit
c1358c9a25

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