Skip to content
This repository was archived by the owner on Jan 24, 2019. It is now read-only.

Commit 913f017

Browse files
committed
修复随机函数bug
1 parent 46dd909 commit 913f017

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/main/java/com/zhazhapan/util/RandomUtils.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,13 @@ public static int getRandomIntegerIgnoreRange(int floor, int ceil, int[]... rang
179179
int result = getRandomInteger(floor, ceil);
180180
for (int[] range : ranges) {
181181
if (range[0] <= result && result <= range[1]) {
182-
result = result - 1 - (range[1] - range[0]);
183-
break;
182+
if (range[0] > floor) {
183+
result = getRandomIntegerIgnoreRange(floor, range[0], ranges);
184+
} else if (range[1] < ceil) {
185+
result = getRandomIntegerIgnoreRange(range[1], ceil, ranges);
186+
} else {
187+
return -1;
188+
}
184189
}
185190
}
186191
return result;

0 commit comments

Comments
 (0)