summaryrefslogtreecommitdiff
path: root/core/math/random_pcg.cpp
diff options
context:
space:
mode:
authorMarco Cognetta <cognetta.marco@gmail.com>2020-12-21 20:25:58 -0500
committerMarco Cognetta <cognetta.marco@gmail.com>2020-12-21 20:25:58 -0500
commit900e55eb70febc4855ad40b95574ac838e6ca234 (patch)
tree129460d55ff540c794ac8562614569739cc1e584 /core/math/random_pcg.cpp
parent2cbc0b641a0d58a88592d52d86634ca2d40da9e4 (diff)
simplify randi_range
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);
}