C implements a random shuffle method
- 2020-12-22 17:45:07
- OfStack
The example of this article shows how C# implements random shuffling. Share to everybody for everybody reference. Specific implementation methods are as follows:
#region Random shuffle
int[] ints = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 };
List<int> list=ints.ToList();
int[] outs = new int[20];
Random rand = new Random();
for (int i = 0; i < 20; i++)
{
int x = rand.Next(list.Count);
outs[i] = list[x];
list.RemoveAt(x);
}
Response.Write("<hr/>");
foreach (int i in outs)
{
Response.Write(i.ToString() + " ");
}
#endregion
Hopefully this article has helped you with your C# programming.