1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-22 19:48:46 +00:00

Add IList<T> overloads for Shuffle<T>()

This commit is contained in:
Oliver Booth 2019-11-16 11:11:03 +00:00
parent 3b0c304f54
commit d1d89de250
No known key found for this signature in database
GPG Key ID: 4B0992B2602C3778

View File

@ -69,5 +69,24 @@
/// <returns>Returns <paramref name="source"/> shuffled.</returns>
public static IEnumerable<T> Shuffle<T>(this IEnumerable<T> source, Random random) =>
source.OrderBy(_ => random.Next());
/// <summary>
/// Shuffles a list.
/// </summary>
/// <typeparam name="T">The collection type.</typeparam>
/// <param name="source">The collection to shuffle.</param>
/// <returns>Returns <paramref name="source"/> shuffled.</returns>
public static IEnumerable<T> Shuffle<T>(this IList<T> source) =>
source.Shuffle(new Random());
/// <summary>
/// Shuffles a list.
/// </summary>
/// <typeparam name="T">The collection type.</typeparam>
/// <param name="source">The collection to shuffle.</param>
/// <param name="random">The <see cref="Random"/> instance.</param>
/// <returns>Returns <paramref name="source"/> shuffled.</returns>
public static IEnumerable<T> Shuffle<T>(this IList<T> source, Random random) =>
source.OrderBy(_ => random.Next());
}
}