Randomize a list of strings in .net

Need to randomize your list or array? Well, here's a snippet for you that will return the list with the items in a random order. It can easily be changed to sort other types of lists (or arrays) as well.
private static Random rng = new Random();

public static List<string> Randomize(List<string> list) {
byte[] order = new byte[list.Count];
string[] tmp = list.ToArray();

Array.Sort(order, tmp);

return tmp.ToList<string>();

Related posts:


comments powered by Disqus