Browse Source

Validate parameters of randi_range()

Tomasz Chabora 6 years ago
parent
commit
d89478975f
1 changed files with 4 additions and 1 deletions
  1. 4 1
      core/math/random_number_generator.h

+ 4 - 1
core/math/random_number_generator.h

@@ -59,7 +59,10 @@ public:
 
 
 	_FORCE_INLINE_ int randi_range(int from, int to) {
 	_FORCE_INLINE_ int randi_range(int from, int to) {
 		unsigned int ret = randbase.rand();
 		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();
 	RandomNumberGenerator();