summaryrefslogtreecommitdiff
path: root/src/random.c
diff options
context:
space:
mode:
authorDiegoisawesome <diego@domoreaweso.me>2017-12-15 00:08:48 -0600
committerDiegoisawesome <diego@domoreaweso.me>2017-12-15 00:08:48 -0600
commite3c366df6489c92a6ac5778b458b815cc8eab75d (patch)
tree89c80f554da617d89641af8a707ccf9c96d5707c /src/random.c
parent8e9428c482d33ac59b5c29d89db0bd5a2e6fdef3 (diff)
parentc9f196cdfea08eefffd39ebc77a150f197e1250e (diff)
Merge remote-tracking branch 'pret/master'
Diffstat (limited to 'src/random.c')
-rw-r--r--src/random.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/random.c b/src/random.c
new file mode 100644
index 000000000..f2f0ede58
--- /dev/null
+++ b/src/random.c
@@ -0,0 +1,32 @@
+#include "global.h"
+#include "random.h"
+
+// The number 1103515245 comes from the example implementation of rand and srand
+// in the ISO C standard.
+
+EWRAM_DATA static u8 sUnknown = 0;
+EWRAM_DATA static u32 sRandCount = 0;
+
+u16 Random(void)
+{
+ gRngValue = 1103515245 * gRngValue + 24691;
+ sRandCount++;
+ return gRngValue >> 16;
+}
+
+void SeedRng(u16 seed)
+{
+ gRngValue = seed;
+ sUnknown = 0;
+}
+
+void SeedRng2(u16 seed)
+{
+ gRng2Value = seed;
+}
+
+u16 Random2(void)
+{
+ gRng2Value = 1103515245 * gRng2Value + 24691;
+ return gRng2Value >> 16;
+}