class Program
{
static Random r = new Random(0);
static void Main(string[] args)
{
List<string> list = new List<string> { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
List<string> result;
int count = 0;
while (count++ < 20)
{
Console.WriteLine("第{0}次轮询", count);
list = new List<string> { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
result = RadomList(list);
foreach (var item in result)
{
Console.Write(item+" ");
}
Console.WriteLine();
}
Console.Read();
}
private static List<string> RadomList(List<string> list)
{
List<string> result = new List<string>();
while (list.Count > 0)
{
int data = r.Next(0, list.Count);
result.Add(list[data]);
list.RemoveAt(data);
}
// result.Add(list[0]);
return result;
}
}
{
static Random r = new Random(0);
static void Main(string[] args)
{
List<string> list = new List<string> { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
List<string> result;
int count = 0;
while (count++ < 20)
{
Console.WriteLine("第{0}次轮询", count);
list = new List<string> { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
result = RadomList(list);
foreach (var item in result)
{
Console.Write(item+" ");
}
Console.WriteLine();
}
Console.Read();
}
private static List<string> RadomList(List<string> list)
{
List<string> result = new List<string>();
while (list.Count > 0)
{
int data = r.Next(0, list.Count);
result.Add(list[data]);
list.RemoveAt(data);
}
// result.Add(list[0]);
return result;
}
}