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)
You are looking for a Shuffle, there are various implementations out there, usually the Fisher-Yates shuffle.
Below a generic implementation taken from here:
Note that this re-orders the list in place, it’s easy enough to refactor it to return a new list if that’s what you want to do.