I'll assume the cards are numbered 0 through 51. The suit is determined by the card number mod 13 and the pip value is the card number mod 4. That way you don't have to store two values for each card.
int deck [52];
int rndNum;
dbRandomize();
// preload the deck
for (int i = 0; i < 52; i++) deck [i] = i;
// randomize the deck
for (int i = 0; i < 52; i++)
{
int temp;
rndNum = dbRND(51);
// swap the currently indexed element with one at the
// random location
temp = deck[i];
deck[i] = deck[rndNum];
deck[rndNum] = temp;
}
This walks through every element of the deck and swaps it with a random location, thus assuring that all elements are shuffled. In the past I've run this routine inside an outer loop, after the initial ordered number, as many as four times to really shuffle the deck. If you don't overwrite the elements of
deck there's no need to re-do the ordered initialization.
If you use a struct'd datatype or a class object for the array you can still do the swap with the appropriate datatype as long as it has a copy constructor.
Lilith, Night Butterfly
I'm not a programmer but I play one in the office