2015-03-15 01:07:47 +00:00
|
|
|
#include "rng.hpp"
|
2018-04-08 20:10:14 +00:00
|
|
|
|
|
|
|
#include <chrono>
|
|
|
|
#include <random>
|
2015-03-15 01:07:47 +00:00
|
|
|
|
2015-04-22 15:58:55 +00:00
|
|
|
namespace Misc
|
|
|
|
{
|
2015-03-15 01:07:47 +00:00
|
|
|
|
2018-04-08 20:10:14 +00:00
|
|
|
std::mt19937 Rng::generator = std::mt19937();
|
|
|
|
|
2015-03-15 01:07:47 +00:00
|
|
|
void Rng::init()
|
|
|
|
{
|
2018-04-08 20:10:14 +00:00
|
|
|
generator.seed(static_cast<unsigned int>(std::chrono::high_resolution_clock::now().time_since_epoch().count()));
|
2015-03-15 01:07:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float Rng::rollProbability()
|
|
|
|
{
|
2018-04-08 20:10:14 +00:00
|
|
|
return std::uniform_real_distribution<float>(0, 1 - std::numeric_limits<float>::epsilon())(generator);
|
2015-03-15 01:07:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
float Rng::rollClosedProbability()
|
|
|
|
{
|
2018-04-08 20:10:14 +00:00
|
|
|
return std::uniform_real_distribution<float>(0, 1)(generator);
|
2015-03-15 01:07:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int Rng::rollDice(int max)
|
|
|
|
{
|
2018-04-21 13:27:07 +00:00
|
|
|
return max > 0 ? std::uniform_int_distribution<int>(0, max - 1)(generator) : 0;
|
2015-03-15 01:07:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|