From 4da7484ed4bc57394d42d49e72ccf731bf3e7a73 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Wed, 18 Dec 2019 13:05:53 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20String.Shuffle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- X10D/src/StringExtensions.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/X10D/src/StringExtensions.cs b/X10D/src/StringExtensions.cs index 71a9025..e1bc43b 100644 --- a/X10D/src/StringExtensions.cs +++ b/X10D/src/StringExtensions.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; + using System.Linq; using System.Net; using System.Security; using System.Text; @@ -150,6 +151,27 @@ return builder.ToString(); } + /// + /// Shuffles the characters in the string. + /// + /// The string to shuffle. + /// Returns a containing the characters in , rearranged. + public static string Shuffle(this string str) + { + return str.Shuffle(new Random()); + } + + /// + /// Shuffles the characters in the string. + /// + /// The string to shuffle. + /// The instance. + /// Returns a containing the characters in , rearranged. + public static string Shuffle(this string str, Random random) + { + return new string(str.ToCharArray().Shuffle(random).ToArray()); + } + /// /// Splits the into chunks that are no greater than in length. ///