📜  c# shuffle array - C# 代码示例

📅  最后修改于: 2022-03-11 14:49:21.092000             🧑  作者: Mango

代码示例4
# cCopyusing System;
using System.Linq;
using System.Security.Cryptography;

namespace randomize_array
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] arr = { 1, 2, 3, 4, 5 };
            Random random = new Random();
            arr = arr.OrderBy(x => random.Next()).ToArray();
            foreach (var i in arr)
            {
                Console.WriteLine(i);
            }
        }
    }
}

3
4
5
1
2