From c63f340d90800895f007de64b7d2d14624263331 Mon Sep 17 00:00:00 2001 From: nthnluu Date: Sun, 28 Jan 2024 21:20:27 -0500 Subject: Created student weenix repository --- user/lib/libc/rand.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 user/lib/libc/rand.c (limited to 'user/lib/libc/rand.c') diff --git a/user/lib/libc/rand.c b/user/lib/libc/rand.c new file mode 100644 index 0000000..711ae8e --- /dev/null +++ b/user/lib/libc/rand.c @@ -0,0 +1,22 @@ +#include + +/* Random int between lo and hi inclusive */ + +/* TODO Fix the rand/srand implementation to use the implementation in the + * (unused) macro which actually has decent pseudo-randomness properties. (No, + * you can't just change the mod base and expect it to still work fine...) */ + +#define RANDOM(lo, hi) \ + ((lo) + \ + (((hi) - (lo) + 1) * (randseed = (randseed * 4096 + 150889) % 714025)) / \ + 714025) + +static unsigned long long randseed = 123456L; + +int rand(void) +{ + randseed = (randseed * 4096 + 150889) % RAND_MAX; + return randseed; +} + +void srand(unsigned int seed) { randseed = seed; } -- cgit v1.2.3-70-g09d2