femto-backend/Femto.Modules.Blog/Emoji/GetRandomEmoji.cs
2025-05-27 00:28:16 +02:00

18 lines
502 B
C#

namespace Femto.Modules.Blog.Emoji;
internal static partial class AllEmoji
{
public static IList<string> GetRandomEmoji(int count) => new Random().TakeRandomly(Emojis).Distinct().Take(count).ToList();
}
internal static class RandomExtensions
{
public static IEnumerable<T> TakeRandomly<T>(this Random rand, ICollection<T> collection)
{
while (true)
{
var idx = rand.Next(collection.Count);
yield return collection.ElementAt(idx);
}
}
}