Merge pull request #741 from nancheung97/v5-dev

修复RandomUtil的randomEleSet方法在某些情况下无法随机的情况
This commit is contained in:
Golden Looly 2020-02-11 16:47:50 +08:00 committed by GitHub
commit da53f9f883
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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));