From 1383c046e035a62962444ffc4f1f7937417299a4 Mon Sep 17 00:00:00 2001 From: Brian Ferguson Date: Wed, 1 Jan 2014 08:59:39 -0700 Subject: [PATCH] MeasureCalc - Limit the amount of unique random numbers to preserve memory. The limit is set at 65535, which "should" be enough. --- Library/MeasureCalc.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Library/MeasureCalc.cpp b/Library/MeasureCalc.cpp index b10c729f..2e4b56bf 100644 --- a/Library/MeasureCalc.cpp +++ b/Library/MeasureCalc.cpp @@ -24,6 +24,7 @@ const int DEFAULT_LOWER_BOUND = 0; const int DEFAULT_UPPER_BOUND = 100; +const int DEFAULT_UNIQUELIMIT = 65535; std::mt19937& GetRandomEngine() { @@ -93,9 +94,14 @@ void MeasureCalc::ReadOptions(ConfigParser& parser, const WCHAR* section) m_LowBound = parser.ReadInt(section, L"LowBound", DEFAULT_LOWER_BOUND); m_HighBound = parser.ReadInt(section, L"HighBound", DEFAULT_UPPER_BOUND); m_UpdateRandom = parser.ReadBool(section, L"UpdateRandom", false); + const size_t range = (m_HighBound - m_LowBound) + 1; m_UniqueRandom = parser.ReadBool(section, L"UniqueRandom", false); - if (!m_UniqueRandom) + if (m_UniqueRandom && range > DEFAULT_UNIQUELIMIT) + { + m_UniqueRandom = false; + } + else if (!m_UniqueRandom) { m_UniqueNumbers.clear(); }