From 093a6d3d4aa716157255f18652d72dc0fada1a29 Mon Sep 17 00:00:00 2001 From: fdai7754 Date: Thu, 8 Feb 2024 20:53:32 +0100 Subject: [PATCH] refactoring: zufallszahlgenerierung in funktion ausgelagert --- src/magiceightball.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/magiceightball.c b/src/magiceightball.c index ef45818..e49720f 100644 --- a/src/magiceightball.c +++ b/src/magiceightball.c @@ -2,9 +2,12 @@ #include #include -int run_magiceightball() { - +int gib_zufallszahl_aus_16() { srand(time(NULL)); + return rand() % 16; +} + +int run_magiceightball() { char antwort[16][100] = { "Ja", @@ -30,7 +33,7 @@ int run_magiceightball() { char fragesatz[100]; fgets(fragesatz, sizeof(fragesatz), stdin); - int randomIndex = rand() % 16; + int randomIndex = gib_zufallszahl_aus_16(); printf("%s\n", antwort[randomIndex]); return 0;