X-Git-Url: https://git.bzium.org/embe/choinka.git/blobdiff_plain/07902d0dc79759db4894d0d83450b1169d082026..50dda836f33a45ca7ab9d053cf98b49cd68092a3:/choinka.c?ds=inline diff --git a/choinka.c b/choinka.c index 1e29614..b10f073 100644 --- a/choinka.c +++ b/choinka.c @@ -24,6 +24,23 @@ atrybut const podstawa = {0, COLOR_YELLOW}; atrybut const podpis = {A_BOLD, COLOR_RED}; atrybut const gwiazdka = {A_BOLD, COLOR_YELLOW}; +void inicjuj_rng() +{ + unsigned ziarno = 0; + FILE* f = fopen("/dev/urandom", "rb"); + if (f != NULL) { + unsigned nowe_ziarno; + if (fread(&nowe_ziarno, sizeof nowe_ziarno, 1, f) == 1) { + ziarno = nowe_ziarno; + } + fclose(f); + } + if (ziarno == 0) { + ziarno = time(NULL); + } + srand(ziarno); +} + char const rysunek[] = " *\n" " /.\\\n" @@ -50,7 +67,7 @@ void ustaw(atrybut const* attr) int main() { - srand(time(NULL)); + inicjuj_rng(); setupterm(NULL, 1, NULL); atrybut const* kolor = &choinka; for (int i = 0; rysunek[i] != '\0'; i++) {