Add an SDL random number generator with independent seeds.
This commit is contained in:
@@ -25,6 +25,20 @@
|
|||||||
|
|
||||||
unsigned long randseed = time(NULL);
|
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 )
|
void fapproach( float& val, float other_val, float to_move )
|
||||||
{
|
{
|
||||||
ASSERT( to_move >= 0 );
|
ASSERT( to_move >= 0 );
|
||||||
|
|||||||
@@ -92,10 +92,15 @@ inline int RandomInt(int nLow, int nHigh)
|
|||||||
return ((Random() >> 2) % (nHigh - nLow + 1)) + nLow;
|
return ((Random() >> 2) % (nHigh - nLow + 1)) + nLow;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Debug new for memory leak tracing
|
/* Alternative: */
|
||||||
//#ifdef _DEBUG
|
class RandomGen
|
||||||
//#define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
|
{
|
||||||
//#endif
|
unsigned long seed;
|
||||||
|
|
||||||
|
public:
|
||||||
|
RandomGen( unsigned long seed = 0 );
|
||||||
|
int operator() ( int maximum = INT_MAX-1 );
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// Simple function for generating random numbers
|
// Simple function for generating random numbers
|
||||||
|
|||||||
Reference in New Issue
Block a user