diff options
author | Lizzy Fleckenstein <lizzy@vlhl.dev> | 2023-12-23 04:45:48 +0100 |
---|---|---|
committer | Lizzy Fleckenstein <lizzy@vlhl.dev> | 2023-12-23 04:45:48 +0100 |
commit | 2237fd9d5081a25ae52b19d2efc381a9b48aa6da (patch) | |
tree | 1a5558e67815013fe502c3d0a3885c61336f3c26 | |
parent | 12f914b5a51e34308437f9a4eccbb33142b3565f (diff) | |
download | cuddles-2237fd9d5081a25ae52b19d2efc381a9b48aa6da.tar.xz |
seed rng at startup
-rw-r--r-- | stage3/main.c | 3 | ||||
-rw-r--r-- | stage3/rng.c | 9 | ||||
-rw-r--r-- | 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 |