From: phfr24 Date: Mon, 17 Nov 2025 17:48:47 +0000 (-0300) Subject: use xorshift instead of rand() X-Git-Url: https://git.wirehaze.ovh/lifeboot.git/commitdiff_plain/7683c065919d1f7d21a6dc47e7c71268762a5c0a?ds=inline use xorshift instead of rand() --- diff --git a/prototype.c b/prototype.c index 2e9ef3f..83b9398 100644 --- a/prototype.c +++ b/prototype.c @@ -1,8 +1,7 @@ +#include #include -#include #include #include -#include #define COLS 80 #define ROWS 25 @@ -15,6 +14,18 @@ #define STR(x) _STR (x) #define _STR(x) #x +static uint16_t xss; /* xs() state */ + +static uint16_t +xs () /* xorshift prng */ +{ + xss ^= (xss << 1); + xss ^= (xss >> 3); + xss ^= (xss << 10); + + return xss; +} + static void clearscr () { @@ -39,7 +50,7 @@ init_grid (char grid[COLS * ROWS]) { for (int i = 0; i < COLS * ROWS; i++) { - if (rand () % INIT_RATIO) + if (xs () % INIT_RATIO) grid[i] = DEAD; else grid[i] = ALIVE; @@ -108,7 +119,7 @@ main () { char grid[COLS * ROWS]; - srand (time (0)); + xss = time (0); init_grid (grid); do