From dd4c85d9c3c72edf2a9e1c2c91682009da5b2791 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Fri, 12 Dec 2008 01:15:51 +0000 Subject: [PATCH] Made random number generators random again. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@2632 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/utils/random_generator.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 // ----------------------------------------------------------------------------