summaryrefslogtreecommitdiff
path: root/core/math/random_pcg.h
diff options
context:
space:
mode:
authorAndrii Doroshenko (Xrayez) <xrayez@gmail.com>2020-12-05 22:48:26 +0200
committerAndrii Doroshenko (Xrayez) <xrayez@gmail.com>2020-12-07 13:50:46 +0200
commitb5107715f19ec122b7ee1a61831291dc0f1d5df0 (patch)
tree99a6e874edfecfb6b011b42eab5ed8a1a846dfe4 /core/math/random_pcg.h
parent3dc8aaaccc642cddbd8d5c1841fef079db5c7edf (diff)
Add ability to restore `RandomNumberGenerator` state
- added `state` as a property to restore internal state of RNG; - `get_seed()` returns last seed used to initialize the state rather than the current state. Co-authored-by: MidZik <matt.idzik1@gmail.com>
Diffstat (limited to 'core/math/random_pcg.h')
-rw-r--r--core/math/random_pcg.h7
1 files changed, 4 insertions, 3 deletions
diff --git a/core/math/random_pcg.h b/core/math/random_pcg.h
index fe6b1b5639..2e257cb5b7 100644
--- a/core/math/random_pcg.h
+++ b/core/math/random_pcg.h
@@ -61,7 +61,7 @@ static int __bsr_clz32(uint32_t x) {
class RandomPCG {
pcg32_random_t pcg;
- uint64_t current_seed; // seed with this to get the same state
+ uint64_t current_seed; // The seed the current generator state started from.
uint64_t current_inc;
public:
@@ -76,13 +76,14 @@ public:
}
_FORCE_INLINE_ uint64_t get_seed() { return current_seed; }
+ _FORCE_INLINE_ void set_state(uint64_t p_state) { pcg.state = p_state; }
+ _FORCE_INLINE_ uint64_t get_state() const { return pcg.state; }
+
void randomize();
_FORCE_INLINE_ uint32_t rand() {
- current_seed = pcg.state;
return pcg32_random_r(&pcg);
}
_FORCE_INLINE_ uint32_t rand(uint32_t bounds) {
- current_seed = pcg.state;
return pcg32_boundedrand_r(&pcg, bounds);
}