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
This commit is contained in:
parent
02f5ae09ef
commit
dd4c85d9c3
@ -20,6 +20,8 @@
|
||||
#include "random_generator.hpp"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <algorithm>
|
||||
#include <ctime>
|
||||
|
||||
std::vector<RandomGenerator*> 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
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user