mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-11 02:28:18 +00:00
c9c7f947b5
This came from a long discussion comparing PCG-* against xoroshiro*. Do not generate integers without bias because it doesn't affect us very much and it is easier to reimplement with modulo.
33 lines
709 B
C++
33 lines
709 B
C++
#ifndef GAME_SERVER_PRNG_H
|
|
#define GAME_SERVER_PRNG_H
|
|
|
|
#include <base/system.h>
|
|
|
|
class CPrng
|
|
{
|
|
public:
|
|
// Creates an unseeded instance.
|
|
CPrng();
|
|
|
|
// The name of the random number generator including the current seed.
|
|
const char *Description() const;
|
|
|
|
// Seeds the random number generator with the given integer. The random
|
|
// sequence obtained by calling `RandomBits()` repeatedly is guaranteed
|
|
// to be the same for the same seed.
|
|
void Seed(uint64 aSeed[2]);
|
|
|
|
// Generates 32 random bits. `Seed()` must be called before calling
|
|
// this function.
|
|
unsigned int RandomBits();
|
|
|
|
private:
|
|
char m_aDescription[64];
|
|
|
|
bool m_Seeded;
|
|
uint64 m_State;
|
|
uint64 m_Increment;
|
|
};
|
|
|
|
#endif // GAME_SERVER_PRNG_H
|