diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-03-01 15:00:32 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-03-01 15:00:32 +0100 |
commit | bd7637248c6ada567537392d3c69541c632e1c56 (patch) | |
tree | f4160671a920b05fecd7eb45442466b4fa7371ca /core/math/random_pcg.h | |
parent | d8cfc5e1c8f5d72bc21d42945aeab01bea508fa3 (diff) | |
parent | 88df5ea8acd423f2213441d84f2e0f9cd0280552 (diff) | |
download | redot-engine-bd7637248c6ada567537392d3c69541c632e1c56.tar.gz |
Merge pull request #88883 from joaoh82/add-weighted-random-method
Add `RandomNumberGenerator::rand_weighted` method
Diffstat (limited to 'core/math/random_pcg.h')
-rw-r--r-- | core/math/random_pcg.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/core/math/random_pcg.h b/core/math/random_pcg.h index cc22b23b70..fa8ad3cfb3 100644 --- a/core/math/random_pcg.h +++ b/core/math/random_pcg.h @@ -59,6 +59,9 @@ static int __bsr_clz32(uint32_t x) { #define LDEXPF(s, e) ldexp(s, e) #endif +template <class T> +class Vector; + class RandomPCG { pcg32_random_t pcg; uint64_t current_seed = 0; // The seed the current generator state started from. @@ -87,6 +90,8 @@ public: return pcg32_boundedrand_r(&pcg, bounds); } + int rand_weighted(const Vector<float> &p_weights); + // Obtaining floating point numbers in [0, 1] range with "good enough" uniformity. // These functions sample the output of rand() as the fraction part of an infinite binary number, // with some tricks applied to reduce ops and branching: |