1. ## Card game help

I am making a card game(that i invented my self)but i need to know how to make it so that i get random cards...i no how to do that but not how to make it so the same card apears again...and i am sorry but the last time i posted a card game i invented some 1 copyed it and said it was there so i can not post my actual code sorry

2. rand() will give you a random number from 0 to RAND_MAX (usually about 32768). Call srand(time(0)) to seed it - oh yes, and include <time.h> too (or <ctime> for C++).

3. i no how to do that but how can i make it so the same card dosnt come up twice

4. In what kind of card game do you draw a random card from the deck? o_O

Anyway...
I'd recommend putting all of your cards into a vector, something like:

std::vector <Card> deck;

Then using deck.push_back() to add on each card in the deck. To draw a card:

Code:
```// Gets a random number within the size of deck.
int randNum = (rand()*(RAND_MAX+1))%deck.size();

// Sets your new card to the correspond card in your deck
Card newCard = deck[randNum];

// Removes that card from the deck - syntax is ugly - could probably be done cleaner.
deck.erase(deck.begin()+(randNum-1), deck.begin()+randNum);```
Should work, but I'm not positive and I'm certainly no expert.

5. k ill try it and experiment

6. Without using the STL. You just need to create a deck, shuffle it and take one of the top at a time.

7. Exactly, a stack. And to "shuffle" it you could use rand().

Is the card game in C++?

8. Originally Posted by sand_man
Without using the STL. You just need to create a deck, shuffle it and take one of the top at a time.
I thought by "a random card" he meant any card from the deck at any time?

Although I guess that's pretty much the same thing as shuffling it once and taking it off the top...hmm.

I'm silly.

9. Woah.. what's a vector and where can I find detailed information on how to use them? cause when I did my card game I just used the deck as a class.. and had bool card[56] containing 1 or 0 if the card is in place or not, then i randomized between 1 and total number of cards left, and finally through a while loop, got that card out of the deck and showed it to the user once.. had some functions like clear_deck(), get_card(), and stuff...

10. sorry for not replying i was in calgary