using System.Collections.Generic;
static Random random = new Random();
int numParticipants = numTeams * 2;
GenerateRandomSchedule(numTeams, numParticipants);
static void GenerateRandomSchedule(int numTeams, int numParticipants)
if (numParticipants % 2 != 0)
Console.WriteLine("The number of participants must be even.");
List<int> participants = new List<int>();
for (int i = 1; i <= numParticipants; i++)
int rounds = numParticipants - 1;
Dictionary<int, int> playerCounts = new Dictionary<int, int>();
for (int i = 0; i < numParticipants; i++)
for (int round = 1; round <= rounds; round++)
Console.WriteLine($"Round {round}:");
for (int i = 0; i < numTeams; i++)
int team2 = (i + round) % numTeams + 1;
Console.WriteLine($"Team {team1} vs. Team {team2}");
List<int> team1Players = Shuffle(participants.GetRange(i * 2, 2));
List<int> team2Players = Shuffle(participants.GetRange((i + round) % numTeams * 2, 2));
Console.WriteLine($" Player {team1Players[0]} vs. Player {team2Players[0]}");
Console.WriteLine($" Player {team1Players[1]} vs. Player {team2Players[1]}");
playerCounts[team1Players[0]]++;
playerCounts[team1Players[1]]++;
playerCounts[team2Players[0]]++;
playerCounts[team2Players[1]]++;
DisplayPlayerCounts(playerCounts);
static List<T> Shuffle<T>(List<T> list)
int k = random.Next(n + 1);
static void DisplayPlayerCounts(Dictionary<int, int> playerCounts)
Console.WriteLine("Player Counts:");
foreach (var entry in playerCounts)
Console.WriteLine($"Player {entry.Key}: {entry.Value} times");