aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Winston2025-10-05 14:40:51 -0400
committerBen Winston2025-10-05 14:42:21 -0400
commitcf26d8ff753fcb8ef15bb7390afc61cafa546e73 (patch)
treed6c150d08bd6e72b10184e07c35c5674fd1420ff
parentefb46d3e1760ce9241d417f7bff8dcf15e534c37 (diff)
get a random seedHEADmaster
-rw-r--r--yhtz.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/yhtz.c b/yhtz.c
index 64b29a2..acaa3f5 100644
--- a/yhtz.c
+++ b/yhtz.c
@@ -1,6 +1,8 @@
+#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
+#include <sys/random.h>
/*
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() {