namespace KIKunstKirstenKlöckner.Extensions { public static class ListExtension { public static IEnumerable PickRandom(this List list, int n) { if (list.Count == 0) { yield break; } if (n <= 0) { throw new ArgumentException("n must be greater than 0: ", nameof(n)); } for (int i = 0; i < n; i++) { int index = Random.Shared.Next(list.Count); yield return list[index]; } } } }