From d5cdae1592522e330bac0e197a449d8328c1d5dc Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Fri, 30 Sep 2011 23:53:23 -0700 Subject: Fix negative chances wrapping to high (Another bug in the language) --- src/common/mt_rand.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/common') diff --git a/src/common/mt_rand.h b/src/common/mt_rand.h index 95f30e5..84d32e5 100644 --- a/src/common/mt_rand.h +++ b/src/common/mt_rand.h @@ -15,7 +15,10 @@ uint32_t mt_random (void); * MRAND(10) returns 0..9 * MPRAND(5,10) returns 5..14 */ -# define MRAND(mod) (mt_random() % (mod)) +// The cast is essential because the result is sometimes +// compared with a possibly negative number. +// Because it's using modulus, high numbers shouldn't happen anyway. +# define MRAND(mod) ((int)(mt_random() % (mod))) # define MPRAND(add, mod) ((add) + MRAND(mod)) #endif // MT_RAND_H -- cgit v1.2.3-70-g09d2