From fc9a6f1416be514e9d26b301d05e7e347560560b Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 3 Nov 2024 22:37:48 -0500 Subject: Add RNGs to the language --- stdlib/threads.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'stdlib/threads.c') diff --git a/stdlib/threads.c b/stdlib/threads.c index beb6771e..3ae2980b 100644 --- a/stdlib/threads.c +++ b/stdlib/threads.c @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -13,6 +14,7 @@ #include "arrays.h" #include "datatypes.h" +#include "rng.h" #include "text.h" #include "threads.h" #include "types.h" @@ -20,9 +22,10 @@ static void *run_thread(Closure_t *closure) { - long seed; - getrandom(&seed, sizeof(seed), 0); - Int$init_random(seed); + uint8_t *random_bytes = GC_MALLOC_ATOMIC(40); + getrandom(random_bytes, 40, 0); + Array_t rng_seed = {.length=40, .data=random_bytes, .stride=1, .atomic=1}; + default_rng = RNG$new(rng_seed); ((void(*)(void*))closure->fn)(closure->userdata); return NULL; } -- cgit v1.2.3