From 7893cfe014258c5fb7f1f17058879d37abd74868 Mon Sep 17 00:00:00 2001 From: yichengxian <13272263301@163.com> Date: Wed, 5 Aug 2020 22:12:32 +0800 Subject: [PATCH] =?UTF-8?q?[bug=E4=BF=AE=E5=A4=8D]=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=A4=9A=E7=BA=BF=E7=A8=8B=E4=B8=8BThreadLocalRandom=E5=85=B1?= =?UTF-8?q?=E4=BA=ABseed=E5=AF=BC=E8=87=B4=E9=9A=8F=E6=9C=BA=E6=95=B0?= =?UTF-8?q?=E4=B8=80=E6=A0=B7,=E6=9D=83=E9=87=8D=E6=A6=82=E7=8E=87bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/cn/hutool/core/lang/WeightRandom.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/hutool-core/src/main/java/cn/hutool/core/lang/WeightRandom.java b/hutool-core/src/main/java/cn/hutool/core/lang/WeightRandom.java index fd5f4dd0e..346232860 100644 --- a/hutool-core/src/main/java/cn/hutool/core/lang/WeightRandom.java +++ b/hutool-core/src/main/java/cn/hutool/core/lang/WeightRandom.java @@ -32,7 +32,7 @@ public class WeightRandom implements Serializable { private static final long serialVersionUID = -8244697995702786499L; private final TreeMap weightMap; - private final Random random; + /** * 创建权重随机获取器 @@ -50,7 +50,7 @@ public class WeightRandom implements Serializable { */ public WeightRandom() { weightMap = new TreeMap<>(); - random = RandomUtil.getRandom(); + } /** @@ -141,6 +141,7 @@ public class WeightRandom implements Serializable { if(MapUtil.isEmpty(this.weightMap)) { return null; } + final Random random = RandomUtil.getRandom(); final double randomWeight = this.weightMap.lastKey() * random.nextDouble(); final SortedMap tailMap = this.weightMap.tailMap(randomWeight, false); return this.weightMap.get(tailMap.firstKey());