Karusell auf ai art seite gefixrt
This commit is contained in:
23
KIKunstKirstenKlöckner/Extensions/ListExtension.cs
Normal file
23
KIKunstKirstenKlöckner/Extensions/ListExtension.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
namespace KIKunstKirstenKlöckner.Extensions
|
||||
{
|
||||
public static class ListExtension
|
||||
{
|
||||
public static IEnumerable<T> PickRandom<T>(this List<T> list, int n)
|
||||
{
|
||||
if (list.Count == 0)
|
||||
{
|
||||
throw new ArgumentException("List cannot be emtpy: ", nameof(list));
|
||||
}
|
||||
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];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user