From 3406748c6612bfd6a4b1b3cd2b51e97fd12f6d88 Mon Sep 17 00:00:00 2001 From: klappstuhl24 Date: Fri, 17 Nov 2023 13:33:05 +0100 Subject: [PATCH] Karusell auf ai art seite gefixrt --- .../Extensions/ListExtension.cs | 23 +++++++++++++++++++ KIKunstKirstenKlöckner/Pages/AiArt.razor | 20 +++++++++------- 2 files changed, 35 insertions(+), 8 deletions(-) create mode 100644 KIKunstKirstenKlöckner/Extensions/ListExtension.cs diff --git a/KIKunstKirstenKlöckner/Extensions/ListExtension.cs b/KIKunstKirstenKlöckner/Extensions/ListExtension.cs new file mode 100644 index 0000000..b448250 --- /dev/null +++ b/KIKunstKirstenKlöckner/Extensions/ListExtension.cs @@ -0,0 +1,23 @@ +namespace KIKunstKirstenKlöckner.Extensions +{ + public static class ListExtension + { + public static IEnumerable PickRandom(this List 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]; + } + } + } +} diff --git a/KIKunstKirstenKlöckner/Pages/AiArt.razor b/KIKunstKirstenKlöckner/Pages/AiArt.razor index fd0fd5f..f84570b 100644 --- a/KIKunstKirstenKlöckner/Pages/AiArt.razor +++ b/KIKunstKirstenKlöckner/Pages/AiArt.razor @@ -6,6 +6,7 @@ @using DataAccess.Data @using DataAccess.Models @using KIKunstKirstenKlöckner.Data +@using KIKunstKirstenKlöckner.Extensions @using System.Diagnostics @inject IJSRuntime JSRuntime @@ -74,15 +75,18 @@ { } -