jeudi 24 décembre 2015

Rand is still not working when im seeding the number

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

I don't understand why i don't get two random numbers, I've tried to seed the numbers but it doesn't 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