mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-15 16:49:55 +00:00
df178ed97c
Fix container regressions See merge request OpenMW/openmw!346 (cherry picked from commit b0aee6f83d4cddb0116284b197913f9687dd9cee) 95e7a22d fix container regressions
50 lines
1,011 B
C++
50 lines
1,011 B
C++
#include "rng.hpp"
|
|
|
|
#include <chrono>
|
|
#include <random>
|
|
|
|
namespace
|
|
{
|
|
Misc::Rng::Seed sSeed;
|
|
}
|
|
|
|
namespace Misc
|
|
{
|
|
|
|
Rng::Seed::Seed() {}
|
|
|
|
Rng::Seed::Seed(unsigned int seed)
|
|
{
|
|
mGenerator.seed(seed);
|
|
}
|
|
|
|
Rng::Seed& Rng::getSeed()
|
|
{
|
|
return sSeed;
|
|
}
|
|
|
|
void Rng::init(unsigned int seed)
|
|
{
|
|
sSeed.mGenerator.seed(seed);
|
|
}
|
|
|
|
float Rng::rollProbability(Seed& seed)
|
|
{
|
|
return std::uniform_real_distribution<float>(0, 1 - std::numeric_limits<float>::epsilon())(seed.mGenerator);
|
|
}
|
|
|
|
float Rng::rollClosedProbability(Seed& seed)
|
|
{
|
|
return std::uniform_real_distribution<float>(0, 1)(seed.mGenerator);
|
|
}
|
|
|
|
int Rng::rollDice(int max, Seed& seed)
|
|
{
|
|
return max > 0 ? std::uniform_int_distribution<int>(0, max - 1)(seed.mGenerator) : 0;
|
|
}
|
|
|
|
unsigned int Rng::generateDefaultSeed()
|
|
{
|
|
return static_cast<unsigned int>(std::chrono::high_resolution_clock::now().time_since_epoch().count());
|
|
}
|
|
}
|