i'm trying to build a class that represents a shuffled deck of cards.
i start by creating and ordered deck but when i try to randomize it things start to go wrong and i cant figure why.
Code:#include <stdlib.h> #include <iostream> using namespace std; #include "deck.h" //deck::deck(); //{ //} void deck::shuffle() { //gernerate an ordered deck of cards for(int i=0; i<4; i++) { for(int j=1; j<14; j++) { m_cards.push_back(i); m_suits.push_back(i); m_cards[i] = j; m_suits[i] = int(i + 3); // cout<<m_cards[i]<<m_suits[i]<<endl; } } //randomize the deck int randNum; srand(5); for(i = 52; i>0; i--) { randNum = rand() % i; m_deck[i] = m_cards[randNum]; m_suitsArray[i] = m_suits[randNum]; m_cards.erase(m_cards.begin() + randNum);//erase the elements that resided at m_suits.erase(m_suits.begin() + randNum);//loc randNumber so that no two cards //can be put in the deck twice cout<<m_deck[i]<<m_suitsArray[i]<<endl; } }



LinkBack URL
About LinkBacks


