summaryrefslogtreecommitdiff
path: root/src/rng.c
diff options
context:
space:
mode:
authorYamaArashi <shadow962@live.com>2017-02-02 16:30:08 -0800
committerYamaArashi <shadow962@live.com>2017-02-02 16:30:30 -0800
commit8f9ed6e585a361e957650b871fc56a0406c2dac8 (patch)
treefc4796bcad3363136dc7130e8c5ee814104a29d7 /src/rng.c
parent39299306e059d82516247aeacd04b680509eef8c (diff)
decompile rng
Diffstat (limited to 'src/rng.c')
-rw-r--r--src/rng.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/rng.c b/src/rng.c
new file mode 100644
index 000000000..9e473ef62
--- /dev/null
+++ b/src/rng.c
@@ -0,0 +1,35 @@
+#include "global.h"
+#include "rng.h"
+
+// The number 1103515245 comes from the example implementation of rand and srand
+// in the ISO C standard.
+
+extern u32 gRngValue;
+extern u32 gRng2Value;
+
+EWRAM_DATA u8 sUnknown = 0;
+EWRAM_DATA u32 sRandCount = 0;
+
+u16 Random()
+{
+ 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;
+}