Created
August 20, 2014 18:27
-
-
Save richardkundl/53b3e7c766e1f3481ef7 to your computer and use it in GitHub Desktop.
Revisions
-
richardkundl created this gist
Aug 20, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ /// <summary> /// Fisher-Yates algorithm with O(n) time complexity /// </summary> /// <param name="array">array to be shuffled</param> /// <returns>shuffled array</returns> public static int[] FisherYates(int[] array) { Random r = new Random(); for (int i = array.Length - 1; i > 0; i--) { int index = r.Next(i); // swap int tmp = array[index]; array[index] = array[i]; array[i] = tmp; } return array; }