Browse Source

修复:RandomUtil的randomEleSet方法在某些情况下无法随机的情况

NanCheung 5 years ago
parent
commit
9e620b8021
1 changed files with 2 additions and 2 deletions
  1. 2 2
      hutool-core/src/main/java/cn/hutool/core/util/RandomUtil.java

+ 2 - 2
hutool-core/src/main/java/cn/hutool/core/util/RandomUtil.java

@@ -8,7 +8,7 @@ import java.security.SecureRandom;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Random;
 import java.util.Set;
@@ -366,7 +366,7 @@ public class RandomUtil {
 			throw new IllegalArgumentException("Count is larger than collection distinct size !");
 		}
 
-		final HashSet<T> result = new HashSet<>(count);
+		final Set<T> result = new LinkedHashSet<>(count);
 		int limit = source.size();
 		while (result.size() < count) {
 			result.add(randomEle(source, limit));