I’m starting to make a simple bridge style card game. And I have been able to get my program to generate random numbers then assign them to a card, but I am having a bit of trouble trying to work out how to make it not spit out the same card more than once. Anyone have any ideas?
Below is the code i have come up with so far.
oh and also, with the random number generator part, i am using the system clock to help make the numbers more random, but i can only get one number per second, is there another way to get random numbers? or is what i have the only way?Code:#include <cstdlib> #include <ctime> #include <iostream> #include <windows.h> using namespace std; // Random number generator, Will return a integer from 0 - 14 int randomNumber(int d) { srand((unsigned)time(0)); d = (rand()%14); } int main() { int i; while (i <= 52) { int card = randomNumber(card); //cout << card << " "; if (card == 14) cout << "A "; else if (card == 13) cout << "K "; else if (card == 12) cout << "Q "; else if (card == 11) cout << "J "; else cout << card << " "; Sleep(1000); i++; } system("pause"); }



LinkBack URL
About LinkBacks



