mirror of https://github.com/stella-emu/stella.git
Remove C-style 'srand()' and use our already existing 'Random' class.
This also fixes a warning of NULL vs. nullptr.
This commit is contained in:
parent
e2f7712d06
commit
5d64f0a9c3
|
@ -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);
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue