// FUNCTION: reset() // Initializes data members that are serialized. void CvRandom::reset(unsigned long ulSeed) { //-------------------------------- // Uninit class uninit(); recordCallStack(); m_ulRandomSeed = ulSeed; m_ulResetCount++; }
unsigned short CvRandom::get(unsigned short usNum, const char* pszLog) { recordCallStack(); m_ulCallCount++; unsigned long ulNewSeed = ((RANDOM_A * m_ulRandomSeed) + RANDOM_C); unsigned short us = ((unsigned short)((((ulNewSeed >> RANDOM_SHIFT) & MAX_UNSIGNED_SHORT) * ((unsigned long)usNum)) / (MAX_UNSIGNED_SHORT + 1))); if ( GC.getLogging() ) { int iRandLogging = GC.getRandLogging(); if (iRandLogging > 0 && (m_bSynchronous || (iRandLogging & RAND_LOGGING_ASYNCHRONOUS_FLAG) != 0)) { CvGame& kGame = GC.getGame(); if (kGame.getTurnSlice() > 0 || ((iRandLogging & RAND_LOGGING_PREGAME_FLAG) != 0)) { FILogFile* pLog = LOGFILEMGR.GetLog("RandCalls.csv", FILogFile::kDontTimeStamp, "Game Turn, Turn Slice, Range, Value, Seed, Instance, Type, Location\n"); if (pLog) { char szOut[1024] = {0}; sprintf_s(szOut, "%d, %d, %u, %u, %u, %8x, %s, %s\n", kGame.getGameTurn(), kGame.getTurnSlice(), (uint)usNum, (uint)us, getSeed(), (uint)this, m_bSynchronous?"sync":"async", (pszLog != NULL)?pszLog:"Unknown"); pLog->Msg(szOut); #if !defined(FINAL_RELEASE) if ((iRandLogging & RAND_LOGGING_CALLSTACK_FLAG) != 0) { #ifdef _DEBUG if (m_bExtendedCallStackDebugging) { // Use the callstack from the extended callstack debugging system const FCallStack &callStack = m_kCallStacks.back(); std::string stackTrace = callStack.toString(true, 6); pLog->Msg(stackTrace.c_str()); } else #endif { #ifdef WIN32 // Get callstack directly FCallStack callStack; FDebugHelper::GetInstance().GetCallStack(&callStack, 0, 8); std::string stackTrace = callStack.toString(true, 6); pLog->Msg(stackTrace.c_str()); #endif } } #endif } } } } m_ulRandomSeed = ulNewSeed; return us; }
void CvRandom::reseed(unsigned long ulNewValue) { recordCallStack(); m_ulResetCount++; m_ulRandomSeed = ulNewValue; }