From 7e23cabfcea31409e2d9bf627f6c9d30d029917d Mon Sep 17 00:00:00 2001 From: Alexander Nutz Date: Sat, 27 Sep 2025 21:39:09 +0200 Subject: [PATCH] getrandomg --- include/globals.h | 8 -------- src/globals.c | 4 ++-- src/main.c | 16 +++++++++------- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/include/globals.h b/include/globals.h index d9bd84e..a0f993c 100644 --- a/include/globals.h +++ b/include/globals.h @@ -40,14 +40,6 @@ // Calculated from TIME_BETWEEN_TICKS #define TICKS_PER_SECOND ((float)1000000 / TIME_BETWEEN_TICKS) -// Initial world generation seed, will be hashed on startup -// Used in generating terrain and biomes -#define INITIAL_WORLD_SEED 0xA103DE6C - -// Initial general RNG seed, will be hashed on startup -// Used in random game events like item drops and mob behavior -#define INITIAL_RNG_SEED 0xE2B9419 - // Size of each bilinearly interpolated area ("minichunk") // For best performance, CHUNK_SIZE should be a power of 2 #define CHUNK_SIZE 8 diff --git a/src/globals.c b/src/globals.c index 1b66086..6cb2fbf 100644 --- a/src/globals.c +++ b/src/globals.c @@ -31,8 +31,8 @@ ssize_t recv_count; uint8_t recv_buffer[MAX_RECV_BUF_LEN] = {0}; -uint32_t world_seed = INITIAL_WORLD_SEED; -uint32_t rng_seed = INITIAL_RNG_SEED; +uint32_t world_seed; +uint32_t rng_seed; uint16_t world_time = 0; uint32_t server_ticks = 0; diff --git a/src/main.c b/src/main.c index d5216f6..02d359b 100644 --- a/src/main.c +++ b/src/main.c @@ -27,6 +27,7 @@ #include #include #include + #include #endif #include #include @@ -506,15 +507,16 @@ int main () { } #endif - // Hash the seeds to ensure they're random enough - world_seed = splitmix64(world_seed); - printf("World seed (hashed): "); + if (0) { // TODO: manual seed + world_seed = splitmix64(world_seed); + } else { + getrandom(&world_seed, 4, GRND_RANDOM); + } + printf("World seed: "); for (int i = 3; i >= 0; i --) printf("%X", (unsigned int)((world_seed >> (8 * i)) & 255)); + printf("\n"); - rng_seed = splitmix64(rng_seed); - printf("\nRNG seed (hashed): "); - for (int i = 3; i >= 0; i --) printf("%X", (unsigned int)((rng_seed >> (8 * i)) & 255)); - printf("\n\n"); + getrandom(&rng_seed, 4, GRND_RANDOM); // Initialize block changes entries as unallocated for (int i = 0; i < MAX_BLOCK_CHANGES; i ++) {