diff options
Diffstat (limited to 'common/random.cpp')
-rw-r--r-- | common/random.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/common/random.cpp b/common/random.cpp index 5a00d48357..be69d39d2d 100644 --- a/common/random.cpp +++ b/common/random.cpp @@ -21,10 +21,23 @@ #include "common/random.h" #include "common/system.h" +#include "common/EventRecorder.h" namespace Common { +RandomSource::RandomSource(const String &name) { + // Use system time as RNG seed. Normally not a good idea, if you are using + // a RNG for security purposes, but good enough for our purposes. + assert(g_system); + uint32 seed = g_system->getMillis(); + setSeed(seed); + + // Register this random source with the event recorder. This might + // reset the seed, so call it *after* the initial seed has been set. + g_eventRec.registerRandomSource(*this, name); +} + RandomSource::RandomSource() { // Use system time as RNG seed. Normally not a good idea, if you are using // a RNG for security purposes, but good enough for our purposes. @@ -33,6 +46,10 @@ RandomSource::RandomSource() { setSeed(seed); } +RandomSource::~RandomSource() { + // TODO: Unregister with g_eventRec +} + void RandomSource::setSeed(uint32 seed) { _randSeed = seed; } |