1
Fork 0
mirror of https://github.com/Steffo99/keep-everything-alive.git synced 2024-11-28 20:14:18 +00:00
keep-everything-alive/Assets/Plugins/RandomIEnumerables/RandomIEnumerables.cs

24 lines
583 B
C#
Raw Normal View History

2020-04-18 14:09:37 +00:00
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());
}
}