From c4f95ca973eb7e6162cacbd5145bf6aa4b3b86b9 Mon Sep 17 00:00:00 2001 From: jsmorley Date: Mon, 31 Aug 2009 17:47:09 +0000 Subject: [PATCH] Committed MattKing's code to generate a random number in a CALC measure. RANDOM Function: Returns a random number between "LowBound" and "HighBound" defined in the measure. Sample usage: [MeasureCalc] Measure=Calc Formula=(Random) LowBound=5 HighBound=100 --- Library/MeasureCalc.cpp | 29 +++++++++++++++++++++++++++++ Library/MeasureCalc.h | 7 +++++++ 2 files changed, 36 insertions(+) diff --git a/Library/MeasureCalc.cpp b/Library/MeasureCalc.cpp index cfdfecd9..9653abcd 100644 --- a/Library/MeasureCalc.cpp +++ b/Library/MeasureCalc.cpp @@ -20,10 +20,19 @@ #include "MeasureCalc.h" #include "Rainmeter.h" +#include +#include hqStrMap* CMeasureCalc::c_VarMap = NULL; int CMeasureCalc::m_Loop = 0; +//====================================== +//MattKing Code Edit :: Start +double CMeasureCalc::m_Random = 0; +double CMeasureCalc::m_LowBound = 0; +double CMeasureCalc::m_HighBound = 0; +//MattKing Code Edit :: End + /* ** CMeasureCalc ** @@ -33,6 +42,12 @@ int CMeasureCalc::m_Loop = 0; CMeasureCalc::CMeasureCalc(CMeterWindow* meterWindow) : CMeasure(meterWindow) { m_Parser = MathParser_Create(NULL); + + //====================================== + //MattKing Code Edit :: Start + srand((unsigned)time(0)); + //MattKing Code Edit :: End + } /* @@ -99,6 +114,7 @@ void CMeasureCalc::UpdateVariableMap(CMeterWindow& meterWindow) // Add the counter double counter = meterWindow.GetUpdateCounter(); StrMap_AddString(c_VarMap, "Counter", &counter); + StrMap_AddString(c_VarMap, "Random", &m_Random); } /* @@ -112,4 +128,17 @@ void CMeasureCalc::ReadConfig(CConfigParser& parser, const WCHAR* section) CMeasure::ReadConfig(parser, section); m_Formula = parser.ReadString(section, L"Formula", L""); + + //MattKing Code Edit :: Start + m_LowBound = parser.ReadFloat(section, L"LowBound", 95); + m_HighBound = parser.ReadFloat(section, L"HighBound", 400); + + int range = (m_HighBound - m_LowBound); + + m_Random = m_LowBound + int(range * rand()/(RAND_MAX + 1.0)); + m_Random = m_LowBound + int(range * rand()/(RAND_MAX + 1.0)); + // For some reason I need two calls to really randomize the number + // I don't have a fix as I dont know much about random numbers + + //MattKing Code Edit :: End } diff --git a/Library/MeasureCalc.h b/Library/MeasureCalc.h index 5208f435..cef70260 100644 --- a/Library/MeasureCalc.h +++ b/Library/MeasureCalc.h @@ -39,6 +39,13 @@ private: static hqStrMap* c_VarMap; static int m_Loop; + + //====================================== + //MattKing Code Edit :: Start + static double m_Random; + static double m_LowBound; + static double m_HighBound; + //MattKing Code Edit :: End }; #endif