summaryrefslogtreecommitdiff
path: root/src/common/mt_rand.h
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2011-03-24 13:57:13 -0700
committerBen Longbons <b.r.longbons@gmail.com>2011-03-24 13:57:13 -0700
commita2306446c86b3333e69b082e41ae76ba71a42d9d (patch)
treeac032fc4566d2ae3091a0dc95329ac86d50b9a23 /src/common/mt_rand.h
parentb6fa80d4c17994771cb796317c52cb8fb7a38a16 (diff)
downloadtmwa-a2306446c86b3333e69b082e41ae76ba71a42d9d.tar.gz
tmwa-a2306446c86b3333e69b082e41ae76ba71a42d9d.tar.bz2
tmwa-a2306446c86b3333e69b082e41ae76ba71a42d9d.tar.xz
tmwa-a2306446c86b3333e69b082e41ae76ba71a42d9d.zip
Optimize common objects, and adjust other objects accordingly.
Major changes still need to be made to each of the servers.
Diffstat (limited to 'src/common/mt_rand.h')
-rw-r--r--src/common/mt_rand.h26
1 files changed, 19 insertions, 7 deletions
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