I have the following code for Shuffle so far,
public static IList<T> Shuffle<T>(this IList<T> list)
{
var rnd = new Random();
return list.OrderBy(element => rnd.Next());
}
and i use it like,
list = list.Shuffle();
i want to be able to use it like
list.Shuffle(); // like list.Reverse();
so basically i want to shuffle by reference
I tried the following code,
public static void Shuffle<T>(this ref IList<T> list)
{
var rnd = new Random();
list.OrderBy(element => rnd.Next());
}
but it doesn’t work.
Any help is greatly appreciated!
I wrote this quite some time ago. Probably worth checking that it is true to the linked algorithm. These sorts of thing are notoriously easy to get subtly wrong.
As per comments below, could be overloaded for more flexibility: