1
Fork 0
mirror of https://github.com/Steffo99/keep-everything-alive.git synced 2024-11-22 17:34:18 +00:00
keep-everything-alive/Assets/Plugins/RandomIEnumerables/RandomIEnumerables.cs
2020-04-18 16:09:37 +02:00

23 lines
583 B
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
// From https://stackoverflow.com/a/2019433/
public static class RandomIEnumerables
{
public static T PickRandom<T>(this IEnumerable<T> source)
{
return source.PickRandom(1).Single();
}
public static IEnumerable<T> PickRandom<T>(this IEnumerable<T> source, int count)
{
return source.Shuffle().Take(count);
}
public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source)
{
return source.OrderBy(x => Guid.NewGuid());
}
}