1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 19:19:55 +00:00
openmw-tes3mp/components/misc/rng.cpp
2018-04-19 15:55:26 +03:00

31 lines
681 B
C++

#include "rng.hpp"
#include <chrono>
#include <random>
namespace Misc
{
std::mt19937 Rng::generator = std::mt19937();
void Rng::init()
{
generator.seed(static_cast<unsigned int>(std::chrono::high_resolution_clock::now().time_since_epoch().count()));
}
float Rng::rollProbability()
{
return std::uniform_real_distribution<float>(0, 1 - std::numeric_limits<float>::epsilon())(generator);
}
float Rng::rollClosedProbability()
{
return std::uniform_real_distribution<float>(0, 1)(generator);
}
int Rng::rollDice(int max)
{
return std::uniform_int_distribution<int>(0, max - 1)(generator);
}
}