修复 RandomUtil中randomEle方法数组越界异常

This commit is contained in:
yichengxian 2020-10-29 14:46:33 +08:00
parent 19eba6086f
commit 8c793de4b2

View File

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