X-Git-Url: https://git.wirehaze.ovh/lifeboot.git/blobdiff_plain/0063f3d6119a904b2e2184793016c05d18c8a3f6..90ffff61d4b6169c5bd8ef942ddc269d1da4bce7:/prototype.c?ds=sidebyside 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