aboutsummaryrefslogtreecommitdiff
path: root/stdlib/threads.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-11-03 22:37:48 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-11-03 22:37:48 -0500
commitfc9a6f1416be514e9d26b301d05e7e347560560b (patch)
tree7d61cc3657c36dde05135f17dbf5923cff177abf /stdlib/threads.c
parent52e3d3fe6f2c3e5051affe155fed364d1a5d623c (diff)
Add RNGs to the language
Diffstat (limited to 'stdlib/threads.c')
-rw-r--r--stdlib/threads.c9
1 files changed, 6 insertions, 3 deletions
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 <ctype.h>
#include <err.h>
+#include <fcntl.h>
#include <gc.h>
#include <math.h>
#include <stdbool.h>
@@ -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;
}