Calc: Use std::mt19937 with a deterministic seed as the random engine

This commit is contained in:
Birunthan Mohanathas 2013-12-08 15:06:01 +02:00
parent ec9c2ef598
commit f5fb87f336
2 changed files with 8 additions and 8 deletions

View File

@ -20,12 +20,16 @@
#include "../Common/MathParser.h"
#include "MeasureCalc.h"
#include "Rainmeter.h"
#include <random>
const int DEFAULT_LOWER_BOUND = 0;
const int DEFAULT_UPPER_BOUND = 100;
std::default_random_engine MeasureCalc::c_RandomEngine =
std::default_random_engine(std::random_device()());
std::mt19937& GetRandomEngine()
{
static std::unique_ptr<std::mt19937> s_Engine(new std::mt19937((uint32_t)time(0)));
return *s_Engine;
}
/*
** The constructor
@ -216,7 +220,7 @@ int MeasureCalc::GetRandom()
else
{
const std::uniform_int_distribution<int> distribution(m_LowBound, m_HighBound);
return distribution(c_RandomEngine);
return distribution(GetRandomEngine());
}
}
@ -230,5 +234,5 @@ void MeasureCalc::UpdateUniqueNumberList()
m_UniqueNumbers[i] = m_LowBound + i;
}
std::shuffle(m_UniqueNumbers.begin(), m_UniqueNumbers.end(), c_RandomEngine);
std::shuffle(m_UniqueNumbers.begin(), m_UniqueNumbers.end(), GetRandomEngine());
}

View File

@ -20,7 +20,6 @@
#define __MEASURECALC_H__
#include "Measure.h"
#include <random>
class MeasureCalc : public Measure
{
@ -51,9 +50,6 @@ private:
std::vector<int> m_UniqueNumbers;
void UpdateUniqueNumberList();
// Uniform Random Number Generator
static std::default_random_engine c_RandomEngine;
};
#endif