mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-26 21:13:51 +00:00
fix: eliminate last std::rand() calls — music shuffle and UI weather
zone_manager.cpp used std::rand() for music track selection with modulo bias and global state. game_screen.cpp used std::rand() for rain/snow particle positions. Both now use local std::mt19937 seeded from random_device. Also removes the global srand(time(nullptr)) call since no code depends on the C rand() seed anymore. No std::rand() or srand() calls remain in the codebase.
This commit is contained in:
parent
a55eacfe70
commit
5583573beb
2 changed files with 18 additions and 9 deletions
|
|
@ -4,6 +4,7 @@
|
|||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <filesystem>
|
||||
#include <random>
|
||||
#include <unordered_set>
|
||||
|
||||
namespace wowee {
|
||||
|
|
@ -409,7 +410,7 @@ void ZoneManager::initialize() {
|
|||
tileToZone[14 * 100 + 16] = 1657;
|
||||
tileToZone[14 * 100 + 17] = 1657;
|
||||
|
||||
std::srand(static_cast<unsigned>(std::time(nullptr)));
|
||||
// Seed removed — music shuffle now uses a local mt19937 (see pickMusicTrack).
|
||||
|
||||
LOG_INFO("Zone manager initialized: ", zones.size(), " zones, ", tileToZone.size(), " tile mappings");
|
||||
}
|
||||
|
|
@ -458,7 +459,8 @@ std::string ZoneManager::getRandomMusic(uint32_t zoneId) {
|
|||
// Avoid playing the same track back-to-back
|
||||
const std::string* pick = pool[0];
|
||||
for (int attempts = 0; attempts < 5; ++attempts) {
|
||||
pick = pool[std::rand() % pool.size()];
|
||||
static std::mt19937 musicRng(std::random_device{}());
|
||||
pick = pool[std::uniform_int_distribution<size_t>(0, pool.size() - 1)(musicRng)];
|
||||
if (*pick != lastPlayedMusic_) break;
|
||||
}
|
||||
lastPlayedMusic_ = *pick;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue