diff --git a/X10D/ListExtensions.cs b/X10D/ListExtensions.cs index 586e4af..c67df16 100644 --- a/X10D/ListExtensions.cs +++ b/X10D/ListExtensions.cs @@ -50,5 +50,24 @@ /// Returns a random element of type from . public static T OneOf(this IList source, Random random) => random.OneOf(source); + + /// + /// Shuffles an enumerable. + /// + /// The collection type. + /// The collection to shuffle. + /// Returns shuffled. + public static IEnumerable Shuffle(this IEnumerable source) => + source.Shuffle(new Random()); + + /// + /// Shuffles an enumerable. + /// + /// The collection type. + /// The collection to shuffle. + /// The instance. + /// Returns shuffled. + public static IEnumerable Shuffle(this IEnumerable source, Random random) => + source.OrderBy(x => random.Next()); } }