Add an SDL random number generator with independent seeds.

This commit is contained in:
Glenn Maynard
2003-07-30 20:31:50 +00:00
parent f741443c76
commit 4262c7fd96
2 changed files with 23 additions and 4 deletions
+14
View File
@@ -25,6 +25,20 @@
unsigned long randseed = time(NULL);
RandomGen::RandomGen( unsigned long seed_ )
{
seed = seed_;
if(seed == 0)
seed = time(NULL);
}
int RandomGen::operator() ( int maximum )
{
seed = 1664525L * seed + 1013904223L;
return (seed >> 2) % (maximum + 1);
}
void fapproach( float& val, float other_val, float to_move )
{
ASSERT( to_move >= 0 );
+9 -4
View File
@@ -92,10 +92,15 @@ inline int RandomInt(int nLow, int nHigh)
return ((Random() >> 2) % (nHigh - nLow + 1)) + nLow;
}
// Debug new for memory leak tracing
//#ifdef _DEBUG
//#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
//#endif
/* Alternative: */
class RandomGen
{
unsigned long seed;
public:
RandomGen( unsigned long seed = 0 );
int operator() ( int maximum = INT_MAX-1 );
};
// Simple function for generating random numbers