Rev 8 | Rev 18 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 8 | Rev 11 | ||
|---|---|---|---|
| Line 205... | Line 205... | ||
| 205 | } |
205 | } |
| 206 | } |
206 | } |
| 207 | 207 | ||
| 208 | // IDA: int __usercall IRandomBetween@<EAX>(int pA@<EAX>, int pB@<EDX>) |
208 | // IDA: int __usercall IRandomBetween@<EAX>(int pA@<EAX>, int pB@<EDX>) |
| 209 | int IRandomBetween(int pA, int pB) { |
209 | int IRandomBetween(int pA, int pB) { |
| - | 210 | #if 1 |
|
| 210 | int num; |
211 | int num; |
| 211 | //char s[32]; // Pierre-Marie Baty -- unused variable |
212 | //char s[32]; // Pierre-Marie Baty -- unused variable |
| 212 | 213 | ||
| 213 | num = rand(); |
214 | num = rand(); |
| 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 (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 |
216 | // 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); |
217 | return pA + ((num * (pB + 1 - pA)) >> 15); |
| 217 | #else |
218 | #else |
| 218 | // If RAND_MAX != 0x7fff, then use floating numbers (alternative is using modulo) |
219 | // If RAND_MAX != 0x7fff, then use floating numbers (alternative is using modulo) |
| 219 | return pA + (int)((pB + 1 - pA) * (num / ((float)RAND_MAX + 1))); |
220 | return pA + (int)((pB + 1 - pA) * (num / ((float)RAND_MAX + 1))); |
| - | 221 | #endif |
|
| - | 222 | #else // Pierre-Marie Baty -- madebr's code -- TODO: test |
|
| - | 223 | long long int a = rand () * (pB + 1 - pA); |
|
| - | 224 | a &= 0x7fffffffffffffff; |
|
| - | 225 | return pA + (a >> 15); |
|
| 220 | #endif |
226 | #endif |
| 221 | } |
227 | } |
| 222 | 228 | ||
| 223 | // IDA: int __usercall PercentageChance@<EAX>(int pC@<EAX>) |
229 | // IDA: int __usercall PercentageChance@<EAX>(int pC@<EAX>) |
| 224 | int PercentageChance(int pC) { |
230 | int PercentageChance(int pC) { |