summaryrefslogtreecommitdiff
path: root/core/math/random_pcg.cpp
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2020-12-22 11:28:59 +0100
committerGitHub <noreply@github.com>2020-12-22 11:28:59 +0100
commit30d469a5e0f70860f3c4ce4508d6564ca389320b (patch)
tree759a4778cacf96d20832e05086c5e5d05c5bfb6b /core/math/random_pcg.cpp
parent6e43c68e40b81005d0c393eced6cf871d1964fbd (diff)
parent900e55eb70febc4855ad40b95574ac838e6ca234 (diff)
Merge pull request #44562 from mcognetta/randi_range_simplification
Simplify `randi_range` implementation
Diffstat (limited to 'core/math/random_pcg.cpp')
-rw-r--r--core/math/random_pcg.cpp12
1 files changed, 2 insertions, 10 deletions
diff --git a/core/math/random_pcg.cpp b/core/math/random_pcg.cpp
index e0768b9403..c39037747a 100644
--- a/core/math/random_pcg.cpp
+++ b/core/math/random_pcg.cpp
@@ -51,16 +51,8 @@ float RandomPCG::random(float p_from, float p_to) {
}
int RandomPCG::random(int p_from, int p_to) {
- int range;
- int min;
- if (p_to > p_from) {
- range = p_to - p_from + 1;
- min = p_from;
- } else if (p_to < p_from) {
- range = p_from - p_to + 1;
- min = p_to;
- } else { // from == to
+ if (p_from == p_to) {
return p_from;
}
- return rand(range) + min;
+ return rand(abs(p_from - p_to) + 1) + MIN(p_from, p_to);
}