diff --git a/X10D/src/EnumerableExtensions.cs b/X10D/src/EnumerableExtensions.cs index 10e937b..ac91337 100644 --- a/X10D/src/EnumerableExtensions.cs +++ b/X10D/src/EnumerableExtensions.cs @@ -8,6 +8,19 @@ namespace X10D /// public static class EnumerableExtensions { + /// + /// Reorganizes the elements in an enumerable by implementing a Fisher-Yates shuffle, and returns th shuffled result. + /// + /// The element type. + /// The to shuffle. + /// Optional. The instance to use for the shuffling. + public static IReadOnlyCollection Shuffled(this IEnumerable source, System.Random? random = null) + { + var list = new List(source); + list.Shuffle(random); + return list.AsReadOnly(); + } + /// /// Splits into chunks of size . /// diff --git a/X10D/src/ListExtensions.cs b/X10D/src/ListExtensions.cs index 92ee7be..5f6cb0d 100644 --- a/X10D/src/ListExtensions.cs +++ b/X10D/src/ListExtensions.cs @@ -60,7 +60,7 @@ namespace X10D /// /// The element type. /// The to shuffle. - /// The instance. + /// Optional. The instance to use for the shuffling. public static void Shuffle(this IList source, System.Random? random = null) { if (source is null) diff --git a/X10D/src/StringExtensions.cs b/X10D/src/StringExtensions.cs index 8c278d0..411377e 100644 --- a/X10D/src/StringExtensions.cs +++ b/X10D/src/StringExtensions.cs @@ -336,7 +336,7 @@ namespace X10D throw new ArgumentNullException(nameof(str)); } - return new string(str.ToCharArray().Shuffle(random).ToArray()); + return new string(str.Shuffled(random).ToArray()); } ///