From a2306446c86b3333e69b082e41ae76ba71a42d9d Mon Sep 17 00:00:00 2001 From: Ben Longbons Date: Thu, 24 Mar 2011 13:57:13 -0700 Subject: Optimize common objects, and adjust other objects accordingly. Major changes still need to be made to each of the servers. --- src/common/mt_rand.h | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'src/common/mt_rand.h') diff --git a/src/common/mt_rand.h b/src/common/mt_rand.h index d798fee..95f30e5 100644 --- a/src/common/mt_rand.h +++ b/src/common/mt_rand.h @@ -1,9 +1,21 @@ -#ifndef __mt_rand_h -#define __mt_rand_h +#ifndef MT_RAND_H +#define MT_RAND_H -void mt_seed (unsigned long seed); -unsigned long mt_reload (void); -unsigned long mt_random (void); -int mt_rand (void); +# include "sanity.h" -#endif /* __mt_rand_h */ +/// Initialize the generator (called automatically with time() if you don't) +void mt_seed (uint32_t seed); +/// Get a random number +uint32_t mt_random (void); + +/** + * ModuloRand and ModuloPlusRand + * These macros are used to replace the vast number of calls to rand()%mod + * TODO eliminate the rest of the calls to rand() + * MRAND(10) returns 0..9 + * MPRAND(5,10) returns 5..14 + */ +# define MRAND(mod) (mt_random() % (mod)) +# define MPRAND(add, mod) ((add) + MRAND(mod)) + +#endif // MT_RAND_H -- cgit v1.2.3-70-g09d2