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