I think I\'ve settled on this as the most simple and unit-testable method for randomising a list, but would be interested to hear of any improvements.
public sta
You want a shuffle, and the best way to do that is the Fisher-Yates shuffle:
public static IList Randomise(IList list, int seed)
{
Random rng = new Random(seed);
List ret = new List(list);
int n = ret.Length;
while (n > 1)
{
n--;
int k = rng.Next(n + 1);
// Simple swap of variables
T tmp = list[k];
ret[k] = ret[n];
ret[n] = tmp;
}
return ret;
}