Possible Duplicate:
Most efficient way to randomly “sort” (Shuffle) a list of integers in C#
How to effectively create a random copy of 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)]);
}
The extension method woud be public static List<T> Shuffle(List<T> this)