Shuffle

#include <iostream>
#include <random>
using namespace std;

void shuffling(string *cards, int n)
{
     for (int i = 0; i < n; i++)
     {
          std::random_device rd;
          std::uniform_int_distribution<int> key(0, i);

          swap(cards[i], cards[key(rd)]);
     }
}

int main()
{
     int players;
     cout << "Enter Players: ";
     cin >> players;
     int count = 1;
     string cards[] = {"2-H", "3-H", "4-H", "5-H", "6-H", "7-H", "8-H", "9-H", "10-H", "J-H", "Q-H", "K-H", "A-H",
                       "2-S", "3-S", "4-S", "5-S", "6-S", "7-S", "8-S", "9-S", "10-S", "J-S", "Q-S", "K-S", "A-S",
                       "2-C", "3-C", "4-C", "5-C", "6-C", "7-C", "8-C", "9-C", "10-C", "J-C", "Q-C", "K-C", "A-C",
                       "2-D", "3-D", "4-D", "5-D", "6-D", "7-D", "8-D", "9-D", "10-D", "J-D", "Q-D", "K-D", "A-D"}; // Hearts, Diamonds, Clubs, Spades
     int n = 52;
     shuffling(cards, n);
     int cardsPerPlayer = ceil(n / players);
     int player = 1;
     cout << "\nPlayer: " << player++ << endl;
     for (int i = 0; i < n; i++)
     {
          cout << cards[i] << " ";
          if (count == cardsPerPlayer && player <= players)
          {
               cout << "\nPlayer: " << player << endl;
               player++;
               count = 0;
          }
          count++;
     }
     cout << endl;
}

Last updated

Was this helpful?