可能重複:
Most efficient way to randomly 「sort」 (Shuffle) a list of integers in C#隨機列表的副本<T>
如何有效地創建List<T>
隨機副本?
List<string> myList = new List<string>();
myList.Add("A");
myList.Add("B");
myList.Add("C");
// Now an extension method or a function which returns a random arrangement of myList:
List<string> GetRandomList()
{
// List<string> result = new List<string>();
// Random rnd = new Random();
// Inside a loop
// result.Add(myList[rnd.Next(1, myList.Count)]);
}
擴展方法woud是public static List<T> Shuffle(List<T> this)
http://stackoverflow.com/questions/2459264/why-is-fisher-yates-the-most-useful-shuffling-algorithm – 2011-05-02 00:12:51
http://stackoverflow.com/questions/1287567/c-is-using -random-and-orderby-a-good-shuffle-algorithm – 2011-05-02 00:13:09
http://stackoverflow.com/questions/3343797/is-this-c-implementation-of-fisher-yates-shuffle-correct – 2011-05-02 00:13:53