From 837194519b2be29aa7665828e4d7cb8035fe1c3b Mon Sep 17 00:00:00 2001 From: MadCamel Date: Sat, 29 Aug 2009 20:43:53 -0400 Subject: Converted to Mersenne Twister for random. Randomerer! Also: Fixed a security problem. Can you find it? --- src/common/utils.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/common/utils.h') diff --git a/src/common/utils.h b/src/common/utils.h index 794a0b6..ba96da1 100644 --- a/src/common/utils.h +++ b/src/common/utils.h @@ -1,3 +1,4 @@ +#include "mt_rand.h" #ifndef NULL #define NULL (void *)0 @@ -38,5 +39,5 @@ * MRAND(10), returns 0-9. * MPRAND(5,10) returns 5-14. */ -#define MRAND(mod) (int) ((float)mod * (rand() / (RAND_MAX + 1.0))) +#define MRAND(mod) (int) ((float)mod * (mt_random() / (RAND_MAX + 1.0))) #define MPRAND(add, mod) add + MRAND(mod) -- cgit v1.2.3-70-g09d2 From dbd9d0321c66deeecf01445f8298aa5076391fbd Mon Sep 17 00:00:00 2001 From: MadCamel Date: Sun, 30 Aug 2009 19:26:28 -0400 Subject: MRAND() no longer uses high-order bits --- src/common/utils.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/common/utils.h') diff --git a/src/common/utils.h b/src/common/utils.h index ba96da1..0b006c3 100644 --- a/src/common/utils.h +++ b/src/common/utils.h @@ -34,10 +34,9 @@ /* * ModuloRand and ModuloPlusRand. These macros are used to replace the - * vast number of calls to rand()%mod which is low-order bits. These - * instead use the high-order bits as suggested in the man page of rand(). + * vast number of calls to rand()%mod .. * MRAND(10), returns 0-9. * MPRAND(5,10) returns 5-14. */ -#define MRAND(mod) (int) ((float)mod * (mt_random() / (RAND_MAX + 1.0))) +#define MRAND(mod) (int) (mt_random() % mod) #define MPRAND(add, mod) add + MRAND(mod) -- cgit v1.2.3-70-g09d2