mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
!204 修复 RandomUti 中数组越界异常
Merge pull request !204 from yichengxian/hutool-ycx
This commit is contained in:
commit
80dd13773a
@ -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