This commit is contained in:
Thomas Jentzsch 2021-10-10 12:06:20 +02:00
commit b65aef7719
3 changed files with 18 additions and 11 deletions

View File

@ -516,16 +516,15 @@ string OSystem::createConsole(const FilesystemNode& rom, const string& md5sum,
// Make sure there always is an id // Make sure there always is an id
if(settings().getString("plusroms.id") == EmptyString) 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"; const char* HEX_DIGITS = "0123456789ABCDEF";
char id_chr[ID_LEN] = {0}; char id_chr[ID_LEN] = {0};
srand(time(NULL)); Random rnd;
for(int i = 0; i < ID_LEN; i++) for(char& c: id_chr)
id_chr[i] = HEX_DIGITS[(rand() % 16)]; c = HEX_DIGITS[rnd.next() % 16];
std::string id_str(id_chr, ID_LEN); settings().setValue("plusroms.id", string(id_chr, ID_LEN));
settings().setValue("plusroms.id", id_str);
} }
myEventHandler->changeStateByEvent(Event::PlusRomsSetupMode); myEventHandler->changeStateByEvent(Event::PlusRomsSetupMode);

View File

@ -18,6 +18,8 @@
#ifndef RANDOM_HXX #ifndef RANDOM_HXX
#define RANDOM_HXX #define RANDOM_HXX
#include <chrono>
#include "bspf.hxx" #include "bspf.hxx"
#include "Serializable.hxx" #include "Serializable.hxx"
@ -32,7 +34,14 @@ class Random : public Serializable
{ {
public: 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); } 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 @return A random number
*/ */
@ -107,7 +116,6 @@ class Random : public Serializable
private: private:
// Following constructors and assignment operators not supported // Following constructors and assignment operators not supported
Random() = delete;
Random(const Random&) = delete; Random(const Random&) = delete;
Random(Random&&) = delete; Random(Random&&) = delete;
Random& operator=(const Random&) = delete; Random& operator=(const Random&) = delete;

View File

@ -38,7 +38,7 @@
<ProjectGuid>{D7FCEC7F-33E1-49DD-A4B0-D5FC222250AD}</ProjectGuid> <ProjectGuid>{D7FCEC7F-33E1-49DD-A4B0-D5FC222250AD}</ProjectGuid>
<RootNamespace>Stella</RootNamespace> <RootNamespace>Stella</RootNamespace>
<Keyword>Win32Proj</Keyword> <Keyword>Win32Proj</Keyword>
<WindowsTargetPlatformVersion>7.0</WindowsTargetPlatformVersion> <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup> </PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
@ -64,7 +64,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet> <CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v141_xp</PlatformToolset> <PlatformToolset>v142</PlatformToolset>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|x64'" Label="Configuration"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Profile|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType> <ConfigurationType>Application</ConfigurationType>