From d511e6c4c24a731497e32395ba54bad52f1adecf Mon Sep 17 00:00:00 2001 From: Logen Kain Date: Sat, 21 Jan 2017 22:12:28 -0700 Subject: [PATCH] Blackjack: Simplified by removing rand_int function --- blackjack/blackjack.c | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-) diff --git a/blackjack/blackjack.c b/blackjack/blackjack.c index 0b4c4cf..f8bdd2b 100644 --- a/blackjack/blackjack.c +++ b/blackjack/blackjack.c @@ -9,8 +9,6 @@ void print_deck (int *deckOfCards); void shuffel (int *array, int n); -static int rand_int(int n); - int main (int argc, char *argv[]) { int i; @@ -51,26 +49,11 @@ void shuffel (int *array, int n){ for (i=n; i>-1 ;i--){ - j = rand_int(i + 1); - - tmp = array[j]; - array[j] = array[i]; - array[i] = tmp; + if (i != 0){ + j = rand() % i; + tmp = array[j]; + array[j] = array[i]; + array[i] = tmp; + } } } - -static int rand_int(int n){ - - int limit = RAND_MAX - RAND_MAX % n; - - int rnd; - - do { - rnd=rand(); - } - while (rnd >= limit); - - return rnd % n; -} - -