# A SHOE! In a card game... ??

This is a discussion on A SHOE! In a card game... ?? within the C++ Programming forums, part of the General Programming Boards category; This is eluding me and I don't know why, here's what I want to do... I have this Baccarat simulater ...

1. ## A SHOE! In a card game... ??

This is eluding me and I don't know why, here's what I want to do...

I have this Baccarat simulater I'm trying to make - baccarat is very similar to blackjack so u can think of it that way if u wish.

I want to have my program shuffle decks of cards into shoes - for those that don't know - a SHOE in a casino is usually 6-8 full decks (52 cards ea.) that are randomly shuffled together and all cards are dealt outta that shoe. I want the user to be able to select the number of decks within the SHOE from 1 to max 8. -- I will also add an infinite shoe which is basically nothing more than a seeded rand() that determines the values of the cards drawn--.

PROBLEM:
I just can't get my hed around the design - I don't need help coding but attacking this problem. I was thinking...

1) using an array or enum to hold an index of the 52 cards in a deck. Or similarly, hold the suits/faces of the cards.
2) I need another array or vector to hold the actual cards - IE this is the SHOE
3) #PROBLEM# How do I shuffle this randomly efficiently, remember I can't use the same card twice (if I give each card an index value) or I can't use more than a certain number of Aces, Kings ( if I design to keep track of suits/faces)... If I use a rand() function how can I create it so that it says that since the value 57 has just been used it can't be used again this shuffle?

How do I avoid getting junk values from my rand() function is the basic jist of my question - I don't want to throw out generated values from rand() b/c it's already been used...

Pleeze help me understand how to acheive this ---

Thanx.

2. Perhaps shove the the numbers which are already used into an array, and then use a do...while loop that breaks only when the generated number is not equal to any number in the array?

3. A small example generating 52 (different) random numbers (sorry it's in C). If you want 2 decks you can change the NOFDECKS define.
Code:
```#include <stdio.h>
#include <time.h>

#define NOFDECKS 1

int main()
{
int i;
int r;
int cards[52] = {0};

srand(time(NULL));

for(i = 0; i < NOFDECKS * 52; i++)
{
r = rand() % 52;
while(cards[r] >= NOFDECKS)
r = (r + 1) % 52;

printf("%d ", r+1);
cards[r]++;
}
return 0;
}```

4. Look at the stl algorigthms, specifically std::random_shuffle

5. ## Shuffle

a simple shuffle could look like this

Code:
```
for( int i = 0; i < CARDS_IN_SHOE; i++)
{
iRand = rand()%CARDS_IN_SHOE;

//Swap cards
temp = cards[i];
cards[i] = cards[iRand];
cards[iRand] = temp;
}

....where cards is the actual shoe of cards...an array of int's in this case```