Anton's got the idea, but you could make it a two-liner:
public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> enumerable)
{
var r = new Random();
return enumerable.OrderBy(x=>r.Next()).ToList();
}
Unfortunately, it can't be lazily evaluated because r
will be out of scope when it does execute. You can create an IEnumerable implementation that encapsulates this code and return that, but that gets more complex.