Infinity Engine v0.6.20
C++ API Documentation
Loading...
Searching...
No Matches
PRNG.hpp
1#pragma once
2
3#include <Infinity/api.h>
4#include <Infinity/Engine/PRNGDistribution.hpp>
5
6#include <pcg/pcg_random.hpp>
7
8namespace Infinity::Engine
9{
10
47class INFINITY_API_PUBLIC PRNG
48{
49 public:
50 typedef uint32_t result_type;
51
94 static uint64_t createSeed();
95
102
110 PRNG(uint64_t seed, uint64_t stream = 0);
111
116
126 void setSeed(uint64_t seed, uint64_t stream = 0);
127
133 inline uint64_t getSeed() const { return _seed; }
134
140 inline uint64_t getStream() const { return _stream; }
141
147 inline uint32_t operator()() { return _gen(); }
148
155 inline uint32_t operator()(uint32_t upper_bound) { return _gen(upper_bound); }
156
162 inline uint32_t next() { return _gen(); }
163
169 int nextInt();
170
176 float nextFloat();
177
185 uint32_t nextBounded(uint32_t l, uint32_t u);
186
194 int nextIntBounded(int l, int u);
195
203 float nextFloatBounded(float l, float u);
204
210 static constexpr size_t period_pow2() { return pcg32::period_pow2(); }
211
217 static constexpr uint32_t min() { return pcg32::min(); }
218
224 static constexpr uint32_t max() { return pcg32::max(); }
225
234 inline void advance(uint64_t delta) { return _gen.advance(delta); }
235
243 inline void backstep(uint64_t delta) { return _gen.backstep(delta); }
244
252 inline void discard(uint64_t delta) { return _gen.discard(delta); }
253
254 private:
255 uint64_t _seed;
256 uint64_t _stream;
257 pcg32 _gen;
258};
259
260}
Pseudo-random number generator for procedural generation.
Definition PRNG.hpp:48
uint32_t result_type
Result type for compatibility with standard library distributions.
Definition PRNG.hpp:50
float nextFloat()
Generates a random float value in the range [0, 1).
uint32_t next()
Generates the next random uint32 value.
Definition PRNG.hpp:162
void backstep(uint64_t delta)
Steps the generator state backward by delta steps.
Definition PRNG.hpp:243
uint32_t nextBounded(uint32_t l, uint32_t u)
Generates a random uint32 value within the specified inclusive range.
int nextIntBounded(int l, int u)
Generates a random integer value within the specified inclusive range.
float nextFloatBounded(float l, float u)
Generates a random float value within the specified inclusive range.
PRNG(uint64_t seed, uint64_t stream=0)
Constructs a PRNG with the specified seed and stream.
static constexpr uint32_t max()
Returns the maximum value the generator can produce.
Definition PRNG.hpp:224
void setSeed(uint64_t seed, uint64_t stream=0)
Sets the seed and stream for the random number generator.
int nextInt()
Generates a random integer value.
void discard(uint64_t delta)
Discards delta random values from the sequence.
Definition PRNG.hpp:252
uint32_t operator()(uint32_t upper_bound)
Function call operator for generating bounded random uint32 values.
Definition PRNG.hpp:155
uint64_t getSeed() const
Gets the current seed value.
Definition PRNG.hpp:133
uint64_t getStream() const
Gets the current stream identifier.
Definition PRNG.hpp:140
static uint64_t createSeed()
Creates a new random seed using system entropy.
uint32_t operator()()
Function call operator for generating random uint32 values.
Definition PRNG.hpp:147
static constexpr size_t period_pow2()
Returns the period of the generator as a power of 2.
Definition PRNG.hpp:210
void advance(uint64_t delta)
Advances the generator state forward by delta steps.
Definition PRNG.hpp:234
PRNG()
Default constructor.
static constexpr uint32_t min()
Returns the minimum value the generator can produce.
Definition PRNG.hpp:217
Definition BaseException.hpp:9