diff --git a/src/utils/random_generator.cpp b/src/utils/random_generator.cpp index 39d16cc32..85e2d69cf 100644 --- a/src/utils/random_generator.cpp +++ b/src/utils/random_generator.cpp @@ -20,6 +20,8 @@ #include "random_generator.hpp" #include +#include +#include std::vector RandomGenerator::m_all_random_generators; @@ -29,6 +31,7 @@ RandomGenerator::RandomGenerator() m_c = 12345; m_all_random_generators.push_back(this); m_random_value = 3141591; + std::srand((unsigned int)std::time(0)); } // RandomGenerator // ---------------------------------------------------------------------------- @@ -62,12 +65,20 @@ void RandomGenerator::seed(int s) // ---------------------------------------------------------------------------- int RandomGenerator::get(int n) { + // This generator is (currently) not good enough, i.e. it often gives + // long sequences of same numbers. And the seeding is not done (the + // mid term goal is to synchronise all random number generators on + // client and server to make less communication necessary). + // For now: just use standard random numbers: + return rand() % n; +#ifdef NOT_USED_ATM m_random_value = m_random_value*m_a+m_c; // Note: the lower bits can have a very short cycle, e.g. for n = 4 the // cycle length is 4, meaning that the same sequence 1,2,3,4 is repeated // over and over again. The higher bits are more random, so the lower // 8 bits are discarded. return (m_random_value >> 8) % n; +#endif } // get // ----------------------------------------------------------------------------