Hi Guys
Looking for one that works without needing seedrnd?
Thks!
These are what I use in my game. Used mainly for speed, rather than just a set seed, should still do though for cross platform stuff.
INLINE
//================================================================================================//
/***********************************************
** Random seed **
***********************************************/
//================================================================================================//
int gRndSeed = 98371;
void Seed(int seed)
{
gRndSeed = seed;
}
//================================================================================================//
/***********************************************
** Random number generator **
***********************************************/
//================================================================================================//
int Rand()
{
int k1;
int ix = gRndSeed;
k1 = ix / 127773;
ix = 16807 * (ix - k1 * 127773) - k1 * 2836;
if (ix < 0)
ix += 2147483647;
gRndSeed = ix;
return gRndSeed;
}
float cRandFloat(float range) // 3 digits after decimal should be plenty for my app.
{
int iRange = (range* 1000);
float result = (float)(Rand()%iRange);
return result * 0.001f;
}
ENDINLINE
FUNCTION SetSeed: seed%
INLINE
Seed( seed );
ENDINLINE
ENDFUNCTION
FUNCTION GetSeed%:
INLINE
return gRndSeed;
ENDINLINE
ENDFUNCTION
FUNCTION RandInt%: range%
INLINE
return Rand()%(range);
ENDINLINE
ENDFUNCTION
FUNCTION RandFloat#: range#
INLINE
return cRandFloat((float)range);
ENDINLINE
ENDFUNCTION
FUNCTION RandFloatRange#: minFloat#, maxFloat#
INLINE
return cRandFloat((float)(maxFloat-minFloat))+minFloat;
ENDINLINE
ENDFUNCTION
FUNCTION RandIntRange%: minInt%, maxInt%
INLINE
return (Rand()%(maxInt-minInt))+minInt;
ENDINLINE
ENDFUNCTION
Thanks!
Will this work for PC and Mac?
Also, are those RND functions faster or slower :)
Should be faster and work the same on any platform.