mardi 22 décembre 2015

Rand is still not working when im seedin the number

Note, the code below is not completely written out, i've allready made a deck and shuffled the cards

I dont understand why i dont get two random numbers, i've tried to seed the numbers but it doesnt seem to work properly. What i would like is for everytime i print out face/suit it should be two different numbers/colors. Where are my mistake?

    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>

    struct card{
        const int *face; 
        const char *suit; 
    };
    typedef struct card Card;

    void dealing(const Card * const wDeck);
    void shuffle(Card * const wDeck);

    int main(){
    srand(time(NULL));
    shuffle(deck);
    dealing(deck);
    return(0);
    }

    void dealing(Card * const wDeck)
    {
        int j;
        j = rand() % 52;
        srand(time(NULL));

        printf("%d of %s\n", wDeck[j].face, wDeck[j].suit);
        printf("%d of %s\n", wDeck[j].face, wDeck[j].suit);
    } 
void shuffle(Card * const wDeck)
{
    int i;     
    int j;    
    Card temp; 

    for (i = 0; i <= 51; i++) {
        j = rand() % 52;
        temp = wDeck[i];
        wDeck[i] = wDeck[j];
        wDeck[j] = temp;
    } 
} 




Aucun commentaire:

Enregistrer un commentaire