summaryrefslogtreecommitdiffstats
path: root/core/math/random_pcg.cpp
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2024-08-28 00:11:35 +0200
committerRémi Verschelde <rverschelde@gmail.com>2024-08-28 00:11:35 +0200
commit2fadd095a7c6090547e9c07abaf3953611d4755e (patch)
tree83e38cfb8d3720e419abffb929df654850b0a0c4 /core/math/random_pcg.cpp
parent8931177d471f7fa0f173998fdd55b8855ec8ebba (diff)
parentab13513403f085ead06fa1a0ddb2b1e60fe3fe02 (diff)
downloadredot-engine-2fadd095a7c6090547e9c07abaf3953611d4755e.tar.gz
Merge pull request #93893 from Togira123/fix-rand-weighted-return-value
Fix `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;
}