You can shuffle your List using Fisher–Yates algorithm in O(n)
; once your iterator equals n, perform a second shuffle and so on.
The pseudocode for it, as presented in wikipedia, is :
To shuffle an array a of n elements (indices 0..n-1):
for i from n ? 1 downto 1 do
j ← random integer with 0 ≤ j ≤ i
exchange a[j] and a[i]
You could even write an extension method for that, something like :
public static Random rand = new Random();
public static List<T> Shuffle<T>(this List<T> original)
{
List<T> lst = new List<T>(original);
for (int i = lst.Count - 1; i >= 1; i--)
{
int j = rand.Next(0, i + 1);
T tmp = lst[j];
lst[j] = lst[i];
lst[i] = tmp;
}
return lst;
}
so that you could generate your shuffled list with
var shuffled = notizen.Shuffle();
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…