mirror of
https://github.com/chibicitiberiu/rainmeter-studio.git
synced 2024-02-24 04:33:31 +00:00
Calc: Use std::mt19937 with a deterministic seed as the random engine
This commit is contained in:
parent
ec9c2ef598
commit
f5fb87f336
@ -20,12 +20,16 @@
|
|||||||
#include "../Common/MathParser.h"
|
#include "../Common/MathParser.h"
|
||||||
#include "MeasureCalc.h"
|
#include "MeasureCalc.h"
|
||||||
#include "Rainmeter.h"
|
#include "Rainmeter.h"
|
||||||
|
#include <random>
|
||||||
|
|
||||||
const int DEFAULT_LOWER_BOUND = 0;
|
const int DEFAULT_LOWER_BOUND = 0;
|
||||||
const int DEFAULT_UPPER_BOUND = 100;
|
const int DEFAULT_UPPER_BOUND = 100;
|
||||||
|
|
||||||
std::default_random_engine MeasureCalc::c_RandomEngine =
|
std::mt19937& GetRandomEngine()
|
||||||
std::default_random_engine(std::random_device()());
|
{
|
||||||
|
static std::unique_ptr<std::mt19937> s_Engine(new std::mt19937((uint32_t)time(0)));
|
||||||
|
return *s_Engine;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** The constructor
|
** The constructor
|
||||||
@ -216,7 +220,7 @@ int MeasureCalc::GetRandom()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
const std::uniform_int_distribution<int> distribution(m_LowBound, m_HighBound);
|
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;
|
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());
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
#define __MEASURECALC_H__
|
#define __MEASURECALC_H__
|
||||||
|
|
||||||
#include "Measure.h"
|
#include "Measure.h"
|
||||||
#include <random>
|
|
||||||
|
|
||||||
class MeasureCalc : public Measure
|
class MeasureCalc : public Measure
|
||||||
{
|
{
|
||||||
@ -51,9 +50,6 @@ private:
|
|||||||
|
|
||||||
std::vector<int> m_UniqueNumbers;
|
std::vector<int> m_UniqueNumbers;
|
||||||
void UpdateUniqueNumberList();
|
void UpdateUniqueNumberList();
|
||||||
|
|
||||||
// Uniform Random Number Generator
|
|
||||||
static std::default_random_engine c_RandomEngine;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user