Subversion Repositories Games.Carmageddon

Rev

Rev 1 | Rev 11 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1 Rev 8
Line 209... Line 209...
209
int IRandomBetween(int pA, int pB) {
209
int IRandomBetween(int pA, int pB) {
210
    int num;
210
    int num;
211
    //char s[32]; // Pierre-Marie Baty -- unused variable
211
    //char s[32]; // Pierre-Marie Baty -- unused variable
212
 
212
 
213
    num = rand();
213
    num = rand();
214
#if RAND_MAX == 0x7fff
214
#if (INT_MAX > 0x7fffffff) && (RAND_MAX == 0x7fff) // Pierre-Marie Baty -- this hack just doesn't work when sizeof(int) == 32 (e.g. on Windows)
215
    //  If RAND_MAX == 0x7fff, then `num` can be seen as a fixed point number with 15 fractional and 17 integral bits
215
    //  If RAND_MAX == 0x7fff, then `num` can be seen as a fixed point number with 15 fractional and 17 integral bits
216
    return pA + ((num * (pB + 1 - pA)) >> 15);
216
    return pA + ((num * (pB + 1 - pA)) >> 15);
217
#else
217
#else
218
    //  If RAND_MAX != 0x7fff, then use floating numbers (alternative is using modulo)
218
    //  If RAND_MAX != 0x7fff, then use floating numbers (alternative is using modulo)
219
    return pA + (int)((pB + 1 - pA) * (num / ((float)RAND_MAX + 1)));
219
    return pA + (int)((pB + 1 - pA) * (num / ((float)RAND_MAX + 1)));