don't hardcode windows value of RAND_MAX and fix namespace issues

This commit is contained in:
Jonathan Gray 2013-04-23 17:42:42 +10:00
parent 0c448c94df
commit 2c2667afcc

View file

@ -972,24 +972,20 @@ inline float Q_crandom( int *seed ) {
// Returns a float min <= x < max (exclusive; will get max - 0.00001; but never max
inline float Q_flrand(float min, float max) {
return ((rand() * (max - min)) / 32768.0F) + min;
return ((rand() * (max - min)) / (float)(RAND_MAX)) + min;
}
// Returns an integer min <= x <= max (ie inclusive)
inline int Q_irand(int min, int max) {
max++; //so it can round down
return ((rand() * (max - min)) >> 15) + min;
return ((rand() * (max - min)) / (RAND_MAX)) + min;
}
//returns a float between 0 and 1.0
inline float random() {
return (rand() / ((float)0x7fff));
}
#define random() ((rand () & 0x7fff) / ((float)0x7fff))
//returns a float between -1 and 1.0
inline float crandom() {
return (2.0F * (random() - 0.5F));
}
#define crandom() (2.0F * (random() - 0.5F))
float erandom( float mean );