Created
January 4, 2014 12:16
-
-
Save Ation/8254863 to your computer and use it in GitHub Desktop.
c#_array_shuffle
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 characters
private static void ShuffleArray(IList<int> array) | |
{ | |
if (array == null) throw new ArgumentNullException("array"); | |
var r = new Random((int) DateTime.Now.Ticks); | |
for (int i = array.Count-1; i >= 0; --i) | |
{ | |
var index = r.Next(i+1); | |
if (index == i) continue; | |
var exchange = array[i]; | |
array[i] = array[index]; | |
array[index] = exchange; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment