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
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);

View File

@ -18,6 +18,8 @@
#ifndef RANDOM_HXX
#define RANDOM_HXX
#include <chrono>
#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;

View File

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