1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-03 17:37:18 +00:00
OpenMW/components/misc/rng.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.4 KiB
C++
Raw Normal View History

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