TIL

Today I Learned


Project maintained by gushwell Hosted on GitHub Pages — Theme by mattgraham

配列の要素をシャッフルするコード

     private static readonly Random _rnd = new Random();

     public  T[] Shuffle<T>(T[] array)
     {
         T[] result = array.ToArray();
         for (int i = result.Length - 1; i > 1; i--)
         {
             int j = _rnd.Next(0, i);
             T a = result[i];
             result[i] = result[j];
             result[j] = a;
         }
         return result;
     }