summaryrefslogtreecommitdiffstats
path: root/core/math/random_pcg.cpp
diff options
context:
space:
mode:
authorTogira <70365614+Togira123@users.noreply.github.com>2024-07-03 12:58:24 +0200
committerTogira <70365614+Togira123@users.noreply.github.com>2024-07-04 02:00:59 +0200
commitab13513403f085ead06fa1a0ddb2b1e60fe3fe02 (patch)
tree35f95e2bb3dd32e6b19eec5d6cacb1f66e57d6ca /core/math/random_pcg.cpp
parent6a13fdcae3662975c101213d47a1eb3a7db63cb3 (diff)
downloadredot-engine-ab13513403f085ead06fa1a0ddb2b1e60fe3fe02.tar.gz
Fix RandomPCG::rand_weighted incorrectly returning -1
Diffstat (limited to 'core/math/random_pcg.cpp')
-rw-r--r--core/math/random_pcg.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/core/math/random_pcg.cpp b/core/math/random_pcg.cpp
index 55787a0b57..c286a60421 100644
--- a/core/math/random_pcg.cpp
+++ b/core/math/random_pcg.cpp
@@ -60,6 +60,11 @@ int64_t RandomPCG::rand_weighted(const Vector<float> &p_weights) {
}
}
+ for (int64_t i = weights_size - 1; i >= 0; --i) {
+ if (weights[i] > 0) {
+ return i;
+ }
+ }
return -1;
}