Unfortunately, if I am reading it correctly nadroj's algorithm contains a

common flaw that will not provide a truly random shuffle.

>> But if its just picking up random cards, how do you stop it picking the same card twice.

If you shuffle the deck, then you just pick cards from the deck one at a time and you will never get the same card twice. The key is to shuffle the deck properly to get an even distribution of possible shuffles.

The link above describes the algorithm in one way (using a second empty deck and randomly selecting cards from the first deck to place in the second).

Another way to look at the algorithm is basically the same, but only uses one deck. Randomly select one card from the deck and place it in the last spot in the array by swapping it with whichever card is there. Then randomly select another card in the array not counting the one at the end and swap it with the next to last card. Continue this way until there is only one card left that you swap with itself and you will have a properly shuffled deck.

Of course, once you understand the proper algorithm for shuffling, I'd suggest not using it, but instead calling the C++ standard library function random_shuffle, which does this work for you (this code assumes you have a vector or array of 52 cards called deck):

Code:

`std::random_shuffle(deck.begin(), deck.end()); // for a vector`

// or

std::random_shuffle(deck, deck + 52); // for an array