dimanche 5 janvier 2020

Using a function to repeatedly generate random numbers

//imported libraries
#include<conio.h>
#include<stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>


//function for drawing cards
int cardValue;

int drawCard(); //function prototype

void main()
{    
    printf("%d \n",drawCard(cardValue));
    printf("%d", drawCard(cardValue));   

    //starting hand 
    _getch();
}

int drawCard()
{
    srand((unsigned)time(NULL));
    cardValue = rand() % 13 + 1;
    return cardValue;
}

I am currently trying to program a blackjack game. Each time the drawcard() function is called I want to generate a random number in the range [1-13].

An example of the desired output would be

1 10

but the outputs I keep getting are

9 9, 10 10, 1 1

etc




Aucun commentaire:

Enregistrer un commentaire