From 2237fd9d5081a25ae52b19d2efc381a9b48aa6da Mon Sep 17 00:00:00 2001 From: Lizzy Fleckenstein Date: Sat, 23 Dec 2023 04:45:48 +0100 Subject: seed rng at startup --- stage3/main.c | 3 +++ stage3/rng.c | 9 +++++++-- stage3/rng.h | 1 + 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 -- cgit v1.2.3