Add String.Shuffle

This commit is contained in:
Oliver Booth 2019-12-18 13:05:53 +00:00
parent 42b59131a0
commit 4da7484ed4
No known key found for this signature in database
GPG Key ID: 0D7F2EF1C8D2B9C0
1 changed files with 22 additions and 0 deletions

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Net; using System.Net;
using System.Security; using System.Security;
using System.Text; using System.Text;
@ -150,6 +151,27 @@
return builder.ToString(); return builder.ToString();
} }
/// <summary>
/// Shuffles the characters in the string.
/// </summary>
/// <param name="str">The string to shuffle.</param>
/// <returns>Returns a <see cref="String"/> containing the characters in <paramref name="str"/>, rearranged.</returns>
public static string Shuffle(this string str)
{
return str.Shuffle(new Random());
}
/// <summary>
/// Shuffles the characters in the string.
/// </summary>
/// <param name="str">The string to shuffle.</param>
/// <param name="random">The <see cref="System.Random"/> instance.</param>
/// <returns>Returns a <see cref="String"/> containing the characters in <paramref name="str"/>, rearranged.</returns>
public static string Shuffle(this string str, Random random)
{
return new string(str.ToCharArray().Shuffle(random).ToArray());
}
/// <summary> /// <summary>
/// Splits the <see cref="String"/> into chunks that are no greater than <paramref name="chunkSize"/> in length. /// Splits the <see cref="String"/> into chunks that are no greater than <paramref name="chunkSize"/> in length.
/// </summary> /// </summary>