Merge pull request #1672
commit
1f1f47431f
@ -1,28 +1,31 @@
|
||||
#include "rng.hpp"
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
|
||||
#include <chrono>
|
||||
#include <random>
|
||||
|
||||
namespace Misc
|
||||
{
|
||||
|
||||
std::mt19937 Rng::generator = std::mt19937();
|
||||
|
||||
void Rng::init()
|
||||
{
|
||||
std::srand(static_cast<unsigned int>(std::time(NULL)));
|
||||
generator.seed(static_cast<unsigned int>(std::chrono::high_resolution_clock::now().time_since_epoch().count()));
|
||||
}
|
||||
|
||||
float Rng::rollProbability()
|
||||
{
|
||||
return static_cast<float>(std::rand() / (static_cast<double>(RAND_MAX)+1.0));
|
||||
return std::uniform_real_distribution<float>(0, 1 - std::numeric_limits<float>::epsilon())(generator);
|
||||
}
|
||||
|
||||
float Rng::rollClosedProbability()
|
||||
{
|
||||
return static_cast<float>(std::rand() / static_cast<double>(RAND_MAX));
|
||||
return std::uniform_real_distribution<float>(0, 1)(generator);
|
||||
}
|
||||
|
||||
int Rng::rollDice(int max)
|
||||
{
|
||||
return static_cast<int>((std::rand() / (static_cast<double>(RAND_MAX)+1.0)) * (max));
|
||||
return std::uniform_int_distribution<int>(0, max - 1)(generator);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue