csharp Fisher-Yates来自https://stackoverflow.com/questions/273313/randomize-a-listt

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了csharp Fisher-Yates来自https://stackoverflow.com/questions/273313/randomize-a-listt相关的知识,希望对你有一定的参考价值。

//https://stackoverflow.com/questions/273313/randomize-a-listt
private static Random rng = new Random();  

public static void Shuffle<T>(this IList<T> list)  
{  
    int n = list.Count;  
    while (n > 1) {  
        n--;  
        int k = rng.Next(n + 1);  
        T value = list[k];  
        list[k] = list[n];  
        list[n] = value;  
    }  
}

以上是关于csharp Fisher-Yates来自https://stackoverflow.com/questions/273313/randomize-a-listt的主要内容,如果未能解决你的问题,请参考以下文章

csharp 来自http://www.codemag.com/Article/1312081

csharp 来自http://www.codemag.com/Article/1312081

csharp 来自http://www.codemag.com/Article/1312081

csharp HMACSHA256来自http://ideone.com/JdpeL

javascript Fisher-Yates Shuffle

javascript Fisher-Yates Shuffle洗牌算法