2020-05-25 13:19:25 +00:00
|
|
|
#ifndef GAME_SERVER_PRNG_H
|
|
|
|
#define GAME_SERVER_PRNG_H
|
|
|
|
|
2020-05-26 08:59:49 +00:00
|
|
|
#include <base/system.h>
|
|
|
|
|
2020-05-25 13:19:25 +00:00
|
|
|
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
|
2020-05-26 08:59:49 +00:00
|
|
|
// sequence obtained by calling `RandomBits()` repeatedly is guaranteed
|
2020-05-25 13:19:25 +00:00
|
|
|
// to be the same for the same seed.
|
2020-05-26 08:59:49 +00:00
|
|
|
void Seed(uint64 aSeed[2]);
|
2020-05-25 13:19:25 +00:00
|
|
|
|
2020-05-26 08:59:49 +00:00
|
|
|
// Generates 32 random bits. `Seed()` must be called before calling
|
|
|
|
// this function.
|
|
|
|
unsigned int RandomBits();
|
2020-05-25 13:19:25 +00:00
|
|
|
|
|
|
|
private:
|
2020-05-26 08:59:49 +00:00
|
|
|
char m_aDescription[64];
|
2020-05-25 13:19:25 +00:00
|
|
|
|
|
|
|
bool m_Seeded;
|
2020-05-26 08:59:49 +00:00
|
|
|
uint64 m_State;
|
|
|
|
uint64 m_Increment;
|
2020-05-25 13:19:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // GAME_SERVER_PRNG_H
|