I am trying to have a "deck" of cards get "shuffled" randomly, but can't seem to figure out why I get a list of the same random number 52 times. The randomizer works for the first iteration but then the same random number gets inserted into the array for the following 51 cards.
//Shuffle Cards
int cardsArray[52] = { 0 };
bool repeatedValue = false;
for (int k = 0; k < 52; k++)
{
srand(time(NULL));
int i;
i = (rand() % 52) + 0;
for (int j = 0; j < 52; j++)
{
if (i == cardsArray[j])
{
repeatedValue = true;
}
}
if (repeatedValue == true)
{
continue;
}
cardsArray[k] = i;
}
Aucun commentaire:
Enregistrer un commentaire