I am making a simple card game, trying to shuffle a deck of cards that i made with a map.
std::map<int, std::string> theDeck;
How could I go about shuffling the items in the deck? I am having issues figuring out the algorithm. This is what I tried, but didn't work.
void shuffleDeck(std::map<int, std::string> & theDeck)
{
srand(time(NULL));
std::map<int, std::string>::iterator it = theDeck.begin();
for (int i = 0; i < 51; i++)
{
int r = i + (rand() % (52-i)); // Random Remaining position
int tempInt = it->first;
std::string tempString = it->second;
theDeck[i] = theDeck[r];
theDeck[r] = it->second;
}
}