Hello其他程序员!我想在我的代码上提供一些帮助。以下程序随机化我的班级'座位顺序。但是,我列表中的某些元素似乎在重复。有没有办法改变这段代码,以便接收不同的座位顺序而不重复我的列表中的任何元素?我提前感谢你们!
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();
}
}