mirror of
https://github.com/Steffo99/keep-everything-alive.git
synced 2024-11-22 09:24:19 +00:00
23 lines
583 B
C#
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());
|
|
}
|
|
}
|