summaryrefslogtreecommitdiff
path: root/src/common/mt_rand.h
diff options
context:
space:
mode:
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