Commit e7106aab authored by deuce's avatar deuce
Browse files

Fix rounding error where random(6) would return 6 one time in 20000 or so.

parent c324d0ee
......@@ -336,13 +336,17 @@ long DLLCALL xp_random(int n)
return(curr % n);
}
#else
float f=0;
double f=0;
int ret;
if(n<2)
return(0);
f=(float)rand()/(float)RAND_MAX;
do {
f=(double)rand()/(double)RAND_MAX;
ret=(n*f);
} while ret==n;
return((int)(n*f));
return(ret);
#endif
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment