summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--stage3/main.c3
-rw-r--r--stage3/rng.c9
-rw-r--r--stage3/rng.h1
3 files changed, 11 insertions, 2 deletions
diff --git a/stage3/main.c b/stage3/main.c
index fd18d6c..abbd33b 100644
--- a/stage3/main.c
+++ b/stage3/main.c
@@ -15,6 +15,7 @@
#include "fs.h"
#include "gfx.h"
#include "clock.h"
+#include "rng.h"
char keymap[256] = { '\0' };
@@ -126,6 +127,8 @@ void kmain()
print_num_pad(features, 2, 32, '0');
print(S("\n"));
+ srand(clock_cycles());
+
interrupts_init();
pic_init();
thread_init();
diff --git a/stage3/rng.c b/stage3/rng.c
index a52b449..01e6597 100644
--- a/stage3/rng.c
+++ b/stage3/rng.c
@@ -1,9 +1,14 @@
#include "rng.h"
+static unsigned long int next = 1;
+
int rand()
{
- static unsigned long int next = 1;
-
next = next * 1103515245 + 12345;
return (unsigned int) (next/65535) % 32768;
}
+
+void srand(int seed)
+{
+ next = seed;
+}
diff --git a/stage3/rng.h b/stage3/rng.h
index fe83ff7..7e3f5ed 100644
--- a/stage3/rng.h
+++ b/stage3/rng.h
@@ -2,5 +2,6 @@
#define RNG_H
int rand();
+void srand(int seed);
#endif