From 913f017ba95d3553d837493dc97e52ab53b592ed Mon Sep 17 00:00:00 2001 From: zhazhapan Date: Mon, 2 Apr 2018 23:47:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=9A=8F=E6=9C=BA=E5=87=BD?= =?UTF-8?q?=E6=95=B0bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/zhazhapan/util/RandomUtils.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/zhazhapan/util/RandomUtils.java b/src/main/java/com/zhazhapan/util/RandomUtils.java index c8e11ce..06c28ee 100644 --- a/src/main/java/com/zhazhapan/util/RandomUtils.java +++ b/src/main/java/com/zhazhapan/util/RandomUtils.java @@ -179,8 +179,13 @@ public static int getRandomIntegerIgnoreRange(int floor, int ceil, int[]... rang int result = getRandomInteger(floor, ceil); for (int[] range : ranges) { if (range[0] <= result && result <= range[1]) { - result = result - 1 - (range[1] - range[0]); - break; + if (range[0] > floor) { + result = getRandomIntegerIgnoreRange(floor, range[0], ranges); + } else if (range[1] < ceil) { + result = getRandomIntegerIgnoreRange(range[1], ceil, ranges); + } else { + return -1; + } } } return result;