X-Git-Url: https://git.bzium.org/embe/choinka.git/blobdiff_plain/399984620d6024e4f2f4943bef9a2229457eed50..50dda836f33a45ca7ab9d053cf98b49cd68092a3:/choinka.c 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++) {