/ Published in: C#

This method shuffles an array. This is the optimum implementation for such an algorithm - O(n).
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
public static void Shuffle<T>(T[] array) { for (int i = 0; i < 10; i++) { int idx = random.Next(i, 10); //swap elements T tmp = array[i]; array[i] = array[idx]; array[idx] = tmp; } }
Comments
