diff options
author | Togira <70365614+Togira123@users.noreply.github.com> | 2024-07-03 12:58:24 +0200 |
---|---|---|
committer | Togira <70365614+Togira123@users.noreply.github.com> | 2024-07-04 02:00:59 +0200 |
commit | ab13513403f085ead06fa1a0ddb2b1e60fe3fe02 (patch) | |
tree | 35f95e2bb3dd32e6b19eec5d6cacb1f66e57d6ca /core/math/random_pcg.cpp | |
parent | 6a13fdcae3662975c101213d47a1eb3a7db63cb3 (diff) | |
download | redot-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.cpp | 5 |
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; } |