Create RandomSeed.h (mt19937 RNG)

This exists to replace the use of RageTimer as a RNG seed, which results in fewer GetTimeSinceStart() calls and better entropy.
This commit is contained in:
sukibaby
2024-08-07 10:05:13 -07:00
committed by teejusb
parent d4ab7b12ed
commit 36892b4e56
4 changed files with 47 additions and 16 deletions
+2 -6
View File
@@ -2,7 +2,6 @@
#include "Player.h"
#include "GameConstantsAndTypes.h"
#include "RageUtil.h"
#include "RageTimer.h"
#include "PrefsManager.h"
#include "GameManager.h"
#include "InputMapper.h"
@@ -40,6 +39,7 @@
#include "GameCommand.h"
#include "LocalizedString.h"
#include "AdjustSync.h"
#include "RandomSeed.h"
#include <cmath>
#include <cstddef>
@@ -3475,11 +3475,7 @@ RString Player::ApplyRandomAttack()
if( GAMESTATE->m_RandomAttacks.size() < 1 )
return "";
//int iAttackToUse = rand() % GAMESTATE->m_RandomAttacks.size();
DateTime now = DateTime::GetNowDate();
int iSeed = now.tm_hour * now.tm_min * now.tm_sec * now.tm_mday;
RandomGen rnd( GAMESTATE->m_iStageSeed * iSeed );
int iAttackToUse = rnd() % GAMESTATE->m_RandomAttacks.size();
int iAttackToUse = GetRandomInt() % GAMESTATE->m_RandomAttacks.size();
return GAMESTATE->m_RandomAttacks[iAttackToUse];
}