summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomasz Chabora <kobewi4e@gmail.com>2019-06-12 03:05:07 +0200
committerTomasz Chabora <kobewi4e@gmail.com>2019-06-12 19:46:07 +0200
commitd89478975f7f97727eea5b865a332efdb4ec9c9d (patch)
tree8841eafe9efc30550711dcb8b5e8ac861fb4cc82
parent30e8b53c380a7bc88fbea768e31bc6b64f27f0ef (diff)
Validate parameters of randi_range()
-rw-r--r--core/math/random_number_generator.h5
1 files changed, 4 insertions, 1 deletions
diff --git a/core/math/random_number_generator.h b/core/math/random_number_generator.h
index 6b6bcdd2cd..a6182a4b33 100644
--- a/core/math/random_number_generator.h
+++ b/core/math/random_number_generator.h
@@ -59,7 +59,10 @@ public:
_FORCE_INLINE_ int randi_range(int from, int to) {
unsigned int ret = randbase.rand();
- return ret % (to - from + 1) + from;
+ if (to < from)
+ return ret % (from - to + 1) + to;
+ else
+ return ret % (to - from + 1) + from;
}
RandomNumberGenerator();