forked from Mirrors/openclonk
Remove RNG implementation from C4Random.h
parent
aeabe28d82
commit
e734f15117
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include "platform/StdScheduler.h"
|
||||
|
||||
#include <pcg/pcg_random.hpp>
|
||||
|
||||
#ifndef INC_C4Particles
|
||||
#define INC_C4Particles
|
||||
|
|
|
@ -21,14 +21,14 @@
|
|||
#include "lib/C4Random.h"
|
||||
#include "control/C4Record.h"
|
||||
|
||||
#include <pcg/pcg_random.hpp>
|
||||
|
||||
int RandomCount = 0;
|
||||
static pcg32 RandomRng;
|
||||
pcg32 SafeRandom;
|
||||
static pcg32 RandomRng, UnsyncedRandomRng;
|
||||
|
||||
void FixedRandom(uint64_t seed)
|
||||
{
|
||||
// for SafeRandom
|
||||
SafeRandom.seed(seed);
|
||||
UnsyncedRandomRng.seed(seed);
|
||||
RandomRng.seed(seed);
|
||||
RandomCount = 0;
|
||||
}
|
||||
|
@ -61,3 +61,22 @@ uint32_t Random(uint32_t iRange)
|
|||
RecordRandom(iRange, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
uint32_t SafeRandom()
|
||||
{
|
||||
return UnsyncedRandomRng();
|
||||
}
|
||||
|
||||
uint32_t SafeRandom(uint32_t iRange)
|
||||
{
|
||||
if (!iRange) return 0u;
|
||||
return UnsyncedRandomRng(iRange);
|
||||
}
|
||||
|
||||
uint32_t SeededRandom(uint64_t iSeed, uint32_t iRange)
|
||||
{
|
||||
if (!iRange) return 0;
|
||||
pcg32 rng(iSeed);
|
||||
return rng(iRange);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,20 +20,18 @@
|
|||
#ifndef INC_C4Random
|
||||
#define INC_C4Random
|
||||
|
||||
#include <pcg/pcg_random.hpp>
|
||||
#include <inttypes.h>
|
||||
|
||||
extern int RandomCount;
|
||||
extern pcg32 SafeRandom;
|
||||
|
||||
// Seeds both the synchronized and the unsynchronized RNGs.
|
||||
void FixedRandom(uint64_t dwSeed);
|
||||
|
||||
// Synchronized RNG.
|
||||
uint32_t Random(uint32_t iRange);
|
||||
|
||||
inline uint32_t SeededRandom(uint64_t iSeed, uint32_t iRange)
|
||||
{
|
||||
if (!iRange) return 0;
|
||||
pcg32 rng(iSeed);
|
||||
return rng(iRange);
|
||||
}
|
||||
// Unsynchronized RNG.
|
||||
uint32_t SafeRandom();
|
||||
uint32_t SafeRandom(uint32_t range);
|
||||
// Generates a single random value from a seed.
|
||||
uint32_t SeededRandom(uint64_t iSeed, uint32_t iRange);
|
||||
|
||||
#endif // INC_C4Random
|
||||
|
|
Loading…
Reference in New Issue