1
0
mirror of https://github.com/oliverbooth/X10D synced 2024-11-09 22:55:42 +00:00

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

View File

@ -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();
}
/// <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>
/// Splits the <see cref="String"/> into chunks that are no greater than <paramref name="chunkSize"/> in length.
/// </summary>