#include <algorithm>
#include <chrono>
#include <iostream>
#include <random>
#include <vector>


template <typename T, typename Rnd>
class Deck
{
public:
    Deck(const std::vector<T>& cards, Rnd& rnd) : cards(cards), rnd(rnd)
    {
        shuffle();
    }
    
    T draw() {
        ++index;
        if (index == cards.size())
        {
            shuffle();
            index = 0;
        }
        return cards[index];
    }
private:
    void shuffle()
    {
        std::cout << "shuffle\n";
        std::shuffle(this->cards.begin(), this->cards.end(), rnd);
    }
    
private:
    std::vector<T> cards;
    std::size_t index = -1;
    Rnd& rnd;
};


int main()
{
    unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
    std::mt19937 rnd(seed);
    Deck<int, std::mt19937> deck({1, 1, 2, 2, 3, 3, 4, 4, 0, 5}, rnd);


    for (int i = 0; i != 42; ++i) {
        std::cout << deck.draw() << std::endl;   
    }
}
