aboutsummaryrefslogtreecommitdiff
path: root/libc/stdlib.c
diff options
context:
space:
mode:
authorFranklin Wei <frankhwei536@gmail.com>2015-02-07 11:03:48 -0500
committerFranklin Wei <frankhwei536@gmail.com>2015-02-07 11:03:48 -0500
commitc0df0ee6437aa2786b1a92bc6af1284958d104c7 (patch)
tree5c6392aa761ba5028387bee72cc73149893ea508 /libc/stdlib.c
parent873a103fb71d6b7b1993a64535a7fa150317ca3c (diff)
downloadkappa-c0df0ee6437aa2786b1a92bc6af1284958d104c7.zip
kappa-c0df0ee6437aa2786b1a92bc6af1284958d104c7.tar.gz
kappa-c0df0ee6437aa2786b1a92bc6af1284958d104c7.tar.bz2
kappa-c0df0ee6437aa2786b1a92bc6af1284958d104c7.tar.xz
new rng, some rework of I/O
Diffstat (limited to 'libc/stdlib.c')
-rw-r--r--libc/stdlib.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/libc/stdlib.c b/libc/stdlib.c
index 356fc33..49f61f1 100644
--- a/libc/stdlib.c
+++ b/libc/stdlib.c
@@ -13,3 +13,26 @@ char* itoa(int val, int base)
return &buf[i+1];
}
+
+static int rand_state = 42;
+
+/* some constants for the RNG */
+#define A 48271
+#define M 2147483647
+#define Q (M/A)
+#define R (M%A)
+
+int rand(void)
+{
+ int tmp = A * (rand_state % Q) - R * (rand_state / Q);
+ if(tmp >= 0)
+ rand_state = tmp;
+ else
+ rand_state = tmp + M;
+ return rand_state;
+}
+
+void srand(unsigned int seed)
+{
+ rand_state = seed;
+}