Hello fellow programmers! I would like some help on my code please. The following program randomizes my class' seating order. However, some elements from my list appear to be repeating. Is there any way to alter this piece of code in order to receive different seating orders without repeating any of the elements in my list? I thank you all in advance!!
List<string> list = new List<string>();
list.AddRange(new String[]
{
"Daria", "Denisa", "Erica",
"Merlin", "Nicoletta", "Mia",
"Lilian", "Karel", "Luveesh",
"Milan", "Oliver","Tea",
"Carlos", "Raneem", "Marsha",
"Uros", "Oguzhan"
});
Random random = new Random();
Console.WriteLine("Type 'x' then hit 'Enter':");
string userInput = Console.ReadLine();
if (userInput == "x")
{
foreach (var item in list)
{
Console.WriteLine("");
Console.WriteLine("Table 1: " + "" + list[random.Next(0, list.Count)] + "," + "" + list[random.Next(1, list.Count)]);
Console.WriteLine("Table 2: " + "" + list[random.Next(2, list.Count)] + "," + "" + list[random.Next(3, list.Count)]);
Console.WriteLine("Table 3: " + "" + list[random.Next(4, list.Count)] + "," + "" + list[random.Next(5, list.Count)]);
Console.WriteLine("Table 4: " + "" + list[random.Next(6, list.Count)] + "," + "" + list[random.Next(7, list.Count)]);
Console.WriteLine("Table 5: " + "" + list[random.Next(8, list.Count)] + "," + "" + list[random.Next(9, list.Count)]);
Console.WriteLine("Table 6: " + "" + list[random.Next(10, list.Count)] + "," + "" + list[random.Next(11, list.Count)]);
Console.WriteLine("Table 7: " + "" + list[random.Next(12, list.Count)] + "," + "" + list[random.Next(13, list.Count)]);
Console.WriteLine("Table 8: " + "" + list[random.Next(14, list.Count)] + "," + "" + list[random.Next(15, list.Count)]);
Console.WriteLine("Table 9: " + "" + list[random.Next(16, list.Count)]);
Console.ReadLine();
}
}