无序排列/随机化数组
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无序排列/随机化数组相关的知识,希望对你有一定的参考价值。
This method shuffles an array. This is the optimum implementation for such an algorithm - O(n).
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; } }
以上是关于无序排列/随机化数组的主要内容,如果未能解决你的问题,请参考以下文章