simplify randi_range

This commit is contained in:
Marco Cognetta
2020-12-21 20:25:58 -05:00
parent 2cbc0b641a
commit 900e55eb70
2 changed files with 22 additions and 10 deletions

View File

@@ -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);
}