From e2f7712d064fc0d9488d1ad723b85859d77ae3fe Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Sat, 9 Oct 2021 20:18:07 -0230 Subject: [PATCH 1/2] Fix compilation in VS, no longer support WinXP. --- src/windows/Stella.vcxproj | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/windows/Stella.vcxproj b/src/windows/Stella.vcxproj index 5e0e99136..1de9faa06 100755 --- a/src/windows/Stella.vcxproj +++ b/src/windows/Stella.vcxproj @@ -38,7 +38,7 @@ {D7FCEC7F-33E1-49DD-A4B0-D5FC222250AD} Stella Win32Proj - 7.0 + 10.0 @@ -64,7 +64,7 @@ Application MultiByte - v141_xp + v142 Application From 5d64f0a9c3390fc26d9ac35db3a8a98292f10847 Mon Sep 17 00:00:00 2001 From: Stephen Anthony Date: Sat, 9 Oct 2021 20:22:59 -0230 Subject: [PATCH 2/2] Remove C-style 'srand()' and use our already existing 'Random' class. This also fixes a warning of NULL vs. nullptr. --- src/emucore/OSystem.cxx | 11 +++++------ src/emucore/Random.hxx | 14 +++++++++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/emucore/OSystem.cxx b/src/emucore/OSystem.cxx index 35f48a87f..729e62490 100644 --- a/src/emucore/OSystem.cxx +++ b/src/emucore/OSystem.cxx @@ -516,16 +516,15 @@ string OSystem::createConsole(const FilesystemNode& rom, const string& md5sum, // Make sure there always is an id if(settings().getString("plusroms.id") == EmptyString) { - const int ID_LEN = 32 - 2; // WE prefix added later + constexpr int ID_LEN = 32 - 2; // WE prefix added later const char* HEX_DIGITS = "0123456789ABCDEF"; char id_chr[ID_LEN] = {0}; - srand(time(NULL)); - for(int i = 0; i < ID_LEN; i++) - id_chr[i] = HEX_DIGITS[(rand() % 16)]; + Random rnd; + for(char& c: id_chr) + c = HEX_DIGITS[rnd.next() % 16]; - std::string id_str(id_chr, ID_LEN); - settings().setValue("plusroms.id", id_str); + settings().setValue("plusroms.id", string(id_chr, ID_LEN)); } myEventHandler->changeStateByEvent(Event::PlusRomsSetupMode); diff --git a/src/emucore/Random.hxx b/src/emucore/Random.hxx index bee3c063f..ec479ce7e 100644 --- a/src/emucore/Random.hxx +++ b/src/emucore/Random.hxx @@ -18,6 +18,8 @@ #ifndef RANDOM_HXX #define RANDOM_HXX +#include + #include "bspf.hxx" #include "Serializable.hxx" @@ -32,7 +34,14 @@ class Random : public Serializable { public: /** - Create a new random number generator + Create a new random number generator with seed based on system time. + */ + explicit Random() { + initSeed(std::chrono::system_clock::now().time_since_epoch().count()); + } + + /** + Create a new random number generator with given seed. */ explicit Random(uInt32 seed) { initSeed(seed); } @@ -46,7 +55,7 @@ class Random : public Serializable } /** - Answer the next random number from the random number generator + Answer the next random number from the random number generator. @return A random number */ @@ -107,7 +116,6 @@ class Random : public Serializable private: // Following constructors and assignment operators not supported - Random() = delete; Random(const Random&) = delete; Random(Random&&) = delete; Random& operator=(const Random&) = delete;