birbmap/Birdmap.BLL/Helpers/IEnumerableExtensions.cs

17 lines
398 B
C#
Raw Normal View History

2020-11-08 18:51:19 +01:00
using System;
using System.Collections.Generic;
using System.Linq;
namespace Birdmap.BLL.Helpers
{
public static class IEnumerableExtensions
{
public static TSource RandomElementAt<TSource>(this IEnumerable<TSource> source, Random random = null)
{
random ??= new Random();
return source.ElementAt(random.Next(source.Count()));
}
}
}