mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
修复 RandomUtil中randomEle方法数组越界异常
This commit is contained in:
parent
19eba6086f
commit
8c793de4b2
@ -310,6 +310,9 @@ public class RandomUtil {
|
||||
* @return 随机元素
|
||||
*/
|
||||
public static <T> T randomEle(List<T> list, int limit) {
|
||||
if (list.size() < limit){
|
||||
limit = list.size();
|
||||
}
|
||||
return list.get(randomInt(limit));
|
||||
}
|
||||
|
||||
@ -335,6 +338,9 @@ public class RandomUtil {
|
||||
* @since 3.3.0
|
||||
*/
|
||||
public static <T> T randomEle(T[] array, int limit) {
|
||||
if (array.length < limit){
|
||||
limit = array.length;
|
||||
}
|
||||
return array[randomInt(limit)];
|
||||
}
|
||||
|
||||
@ -606,4 +612,5 @@ public class RandomUtil {
|
||||
|
||||
return DateUtil.offset(baseDate, dateField, randomInt(min, max));
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user