shuffling a packet of cards

Hey guys, I know you can use rand_shuffle or something along the lines to shuffle a packet of cards but I want to see if I could do it just using srand(time(0)) in less lines. However, it doesnt seem to be printing all the values. Help would be much appreciated!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <cmath>
#include <ctime>
#include <string>

using namespace std;

int main() {
	
	string randomCards[52];
	
	string initialCards[] = {"One of Spades", "One of Hearts", "One of Diamonds", "One of Clubs", "Two of Spades", "Two of Hearts", "Two of Diamonds", "Two of Clubs", "Three of Spades", "Three of Hearts", "Three of Diamonds", "Three of Clubs", "Four of Spades", "Four of Hearts", "Four of Diamonds", "Four of Clubs", "Five of Spades", "Five of Hearts", "Five of Diamonds", "Five of Clubs", "Six of Spades", "Six of Hearts", "Six of Diamonds", "Six of Clubs", "Seven of Spades", "Seven of Hearts", "Seven of Diamonds", "Seven of Clubs", "Eight of Spades", "Eight of Hearts", "Eight of Diamonds", "Eight of Clubs", "Nine of Spades", "Nine of Hearts", "Nine of Diamonds", "Nine of Clubs", "Ten of Spades", "Ten of Hearts", "Ten of Diamonds", "Ten of Clubs", "Jack of Spades", "Jack of Hearts", "Jack of Diamonds", "Jack of Clubs", "Queen of Spades", "Queen of Hearts", "Queen of Diamonds", "Queen of Clubs", "King of Spades", "King of Hearts", "King of Diamonds", "King of Clubs", "Ace of Spades", "Ace of Hearts", "Ace of Diamonds", "Ace of Clubs"};
		
		srand(time(0));
		
		for (int c = 0; c < 52; c++) 
		{
			while (randomCards[rand()%52] != "") 
			{
				sleep(1);
			}		
					
			while (randomCards[rand()%52] == "") 
			{
				randomCards[rand()%52] = initialCards[c];
				break;
			}
		}
		
		for (int p = 0; p < 52; p++) 
		{
			cout << randomCards[p] << ", ";
		}

}


The output doesnt print all the cards. Any ideas?
First read this: http://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle

Paying extra attention to the sections on 'Implementation errors' and 'Modulo bias'
Topic archived. No new replies allowed.