mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-22 19:58:49 +00:00
✨ Add String.Shuffle
This commit is contained in:
parent
42b59131a0
commit
4da7484ed4
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user