Skip to content

Instantly share code, notes, and snippets.

@Ation
Created January 4, 2014 12:16
Show Gist options
  • Save Ation/8254863 to your computer and use it in GitHub Desktop.
Save Ation/8254863 to your computer and use it in GitHub Desktop.
c#_array_shuffle
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