i'm a student and very new to C++, i figured i wanted to try the notions i recently learned to make a little card game.
I built a Class card that stores the value and the suit, here is the constructor :
Card::Card(unsigned int value, unsigned int color, unsigned int id)
:
_value(value),
_color(color),
_id(id)
{
}
Then i made a Deck class (.hpp below) :
class Deck
{
public:
Deck();
~Deck();
void add(Card card);
void remove();
void randomize();
void display();
std::vector<Card> getCards()const;
private:
std::vector<Card> cards;
};
Constructor :
Deck::Deck()
{
int i = 0;
while (i < 52)
{
this->cards.push_back(Card( i%13, i%4, i));
i++;
}
}
my problem is with the Function randomize() , when i call it the output remains the same no matter what, my school asks us to compile with -std=c++98 so i first tried the simple std::random_shuffle(cards.begin(),cards.end())
approach but the output seemed to never change.
i tried in C++11 with std::shuffle
but have no more success, the decks stays ordered.
here is my randomize function :
void Deck::randomize()
{
std::random_device rd;
std::default_random_engine rng(rd());
std::shuffle(this->cards.begin(), this->cards.end(), rng);
}
This is my first post on stack overflow, please tell me if i am not formatting questions properly, i will change it in the future.