I am having trouble with shuffling a deck of cards in C++. I have a deck of cards class. Within the class I have a vector of objects, which are the cards within the deck, and I am trying to shuffle the elements within the vector to shuffle the cards. However, the function I wrote to do it appears to be just shifting everything over every iteration instead of swapping it with another random element within the vector. I'm sure its something really simple and stupid that I am missing, but I just haven't been able to figure it out yet. Any help would be greatly appreciated. Thanks.
void shuffle(int seed = 0)
{
for (int i = 0; i < 100; i += 1)
{
for (unsigned int i = 0; i < deck.size(); i++)
{
card *swap = deck[i];
srand(time(NULL) + seed);
int temp = rand() % 52;
deck[i] = deck[temp];
deck[temp] = swap;
}
cout << "shuffled deck: ";
for (unsigned int i = 0; i < deck.size(); i++)
cout << deck[i]->compare() << " ";
cout << endl;
}
}
This is being called within a probability function I made, inside a loop. The seed for the shuffle function is the iteration of the loop.