From cf26d8ff753fcb8ef15bb7390afc61cafa546e73 Mon Sep 17 00:00:00 2001 From: Ben Winston Date: Sun, 5 Oct 2025 14:40:51 -0400 Subject: get a random seed --- yhtz.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/yhtz.c b/yhtz.c index 64b29a2..acaa3f5 100644 --- a/yhtz.c +++ b/yhtz.c @@ -1,6 +1,8 @@ +#include #include #include #include +#include /* 0000 0000 0000 0000 0000 0000 0000 0000 @@ -168,13 +170,20 @@ int turn_count(yhtz_state* state) { return ret; } +uint16_t init_seed() { + uint8_t buf[2]; + ssize_t ret = getrandom(&buf, 2, 0); + assert(ret == 2); + return (uint16_t)(buf[0] << 8 | buf[1]); +} + void init_yhtz_state(yhtz_state* state) { state->topflag_w_roll = 0; state->topscore = 0; state->botflag = 0; state->botscore = 0; state->dice = 0; - state->seed = 13; /* TODO this isn't random */ + state->seed = init_seed(); } void main() { -- cgit v1.2.3