随机把数组内的元素打乱,重新排列
public static void Shuffle<T>(T[] array) { Random random = new Random(); 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; } }
随机把数组内的元素打乱,重新排列
public static void Shuffle<T>(T[] array) { Random random = new Random(); 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; } }