summaryrefslogtreecommitdiff
path: root/src/common/mt_rand.h
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2011-09-10 16:12:07 -0700
committerBen Longbons <b.r.longbons@gmail.com>2011-09-10 16:12:07 -0700
commitf841b6fdcc802e73d52da0e67ee192c0c2c1c7e1 (patch)
treed9b013ab252968ec1e90e721f7b2ab819af0acb0 /src/common/mt_rand.h
parent5939e1bec75f2550d3ce109b9cd9a5d22c0626c2 (diff)
parent723fb5d3431b847526c433a13aa74485cfb564a3 (diff)
downloadtmwa-f841b6fdcc802e73d52da0e67ee192c0c2c1c7e1.tar.gz
tmwa-f841b6fdcc802e73d52da0e67ee192c0c2c1c7e1.tar.bz2
tmwa-f841b6fdcc802e73d52da0e67ee192c0c2c1c7e1.tar.xz
tmwa-f841b6fdcc802e73d52da0e67ee192c0c2c1c7e1.zip
Merge commit '723fb5d3431b847526c433a13aa74485cfb564a3'
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