2015-04-22 15:58:55 +00:00
|
|
|
#ifndef OPENMW_COMPONENTS_MISC_RNG_H
|
|
|
|
#define OPENMW_COMPONENTS_MISC_RNG_H
|
2015-03-15 01:07:47 +00:00
|
|
|
|
|
|
|
#include <cassert>
|
2018-04-08 20:10:14 +00:00
|
|
|
#include <random>
|
2022-03-17 15:35:34 +00:00
|
|
|
#include <string_view>
|
2015-03-15 01:07:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
Provides central implementation of the RNG logic
|
|
|
|
*/
|
2022-03-06 13:58:16 +00:00
|
|
|
namespace Misc::Rng
|
2015-03-15 01:07:47 +00:00
|
|
|
{
|
2022-03-22 15:09:36 +00:00
|
|
|
/// The use of a rather minimalistic prng is preferred to avoid saving a lot of state in the save game.
|
2022-03-17 15:35:34 +00:00
|
|
|
using Generator = std::minstd_rand;
|
2022-03-06 13:58:16 +00:00
|
|
|
|
|
|
|
Generator& getGenerator();
|
|
|
|
|
2022-03-17 15:35:34 +00:00
|
|
|
std::string serialize(const Generator& prng);
|
|
|
|
void deserialize(std::string_view data, Generator& prng);
|
|
|
|
|
2022-03-06 13:58:16 +00:00
|
|
|
/// returns default seed for RNG
|
|
|
|
unsigned int generateDefaultSeed();
|
2018-04-08 20:10:14 +00:00
|
|
|
|
2015-03-15 01:07:47 +00:00
|
|
|
/// seed the RNG
|
2022-03-06 13:58:16 +00:00
|
|
|
void init(unsigned int seed = generateDefaultSeed());
|
2015-03-15 01:07:47 +00:00
|
|
|
|
|
|
|
/// return value in range [0.0f, 1.0f) <- note open upper range.
|
2022-03-07 10:03:13 +00:00
|
|
|
float rollProbability();
|
|
|
|
float rollProbability(Generator& prng);
|
2022-09-22 18:26:05 +00:00
|
|
|
|
2015-03-15 01:07:47 +00:00
|
|
|
/// return value in range [0.0f, 1.0f] <- note closed upper range.
|
2022-03-07 10:03:13 +00:00
|
|
|
float rollClosedProbability();
|
|
|
|
float rollClosedProbability(Generator& prng);
|
2015-03-15 01:07:47 +00:00
|
|
|
|
|
|
|
/// return value in range [0, max) <- note open upper range.
|
2022-03-07 10:03:13 +00:00
|
|
|
int rollDice(int max);
|
|
|
|
int rollDice(int max, Generator& prng);
|
2015-03-15 01:07:47 +00:00
|
|
|
|
|
|
|
/// return value in range [0, 99]
|
2022-03-07 10:03:13 +00:00
|
|
|
inline int roll0to99(Generator& prng)
|
|
|
|
{
|
|
|
|
return rollDice(100, prng);
|
|
|
|
}
|
|
|
|
inline int roll0to99()
|
|
|
|
{
|
|
|
|
return rollDice(100);
|
|
|
|
}
|
2015-03-15 01:07:47 +00:00
|
|
|
|
2022-03-07 10:03:13 +00:00
|
|
|
float deviate(float mean, float deviation);
|
|
|
|
float deviate(float mean, float deviation, Generator& prng);
|
2015-03-15 01:07:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|