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