summaryrefslogtreecommitdiff
path: root/Source/Kernel/Library
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2009-10-11 16:46:46 +0200
committerAlexis211 <alexis211@gmail.com>2009-10-11 16:46:46 +0200
commit5b9f35ec7509e169f58500b66712eafb075d0b36 (patch)
tree64100c0535b9ad09a63d9900e886da6982818f20 /Source/Kernel/Library
parent378518140711bf19a80218711a018e8fd28d3ca7 (diff)
downloadMelon-5b9f35ec7509e169f58500b66712eafb075d0b36.tar.gz
Melon-5b9f35ec7509e169f58500b66712eafb075d0b36.zip
Added a simple random generator
Diffstat (limited to 'Source/Kernel/Library')
-rw-r--r--Source/Kernel/Library/Rand.ns.cpp18
-rw-r--r--Source/Kernel/Library/Rand.ns.h12
2 files changed, 30 insertions, 0 deletions
diff --git a/Source/Kernel/Library/Rand.ns.cpp b/Source/Kernel/Library/Rand.ns.cpp
new file mode 100644
index 0000000..e568678
--- /dev/null
+++ b/Source/Kernel/Library/Rand.ns.cpp
@@ -0,0 +1,18 @@
+#include "Rand.ns.h"
+
+namespace Rand {
+
+u32int m = 2073741824, a = 50000, b = 1534;
+u64int current = RANDOM_SEED;
+
+u64int rand() {
+ current = (u32int)(a*current + b);
+ while (current > m) current -= m;
+ return current;
+}
+
+u64int max() {
+ return m;
+}
+
+}
diff --git a/Source/Kernel/Library/Rand.ns.h b/Source/Kernel/Library/Rand.ns.h
new file mode 100644
index 0000000..3598de0
--- /dev/null
+++ b/Source/Kernel/Library/Rand.ns.h
@@ -0,0 +1,12 @@
+#ifndef DEF_RAND_NS_H
+#define DEF_RAND_NS_H
+
+#include <Core/common.wtf.h>
+
+namespace Rand {
+ u64int rand();
+ u64int max();
+}
+
+#endif
+