diff --git a/X10D/src/CharExtensions.cs b/X10D/src/CharExtensions.cs
index 328f53f..fe76e58 100644
--- a/X10D/src/CharExtensions.cs
+++ b/X10D/src/CharExtensions.cs
@@ -3,6 +3,10 @@
#region Using Directives
using System;
+ using System.Collections;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
#endregion
@@ -11,6 +15,58 @@
///
public static class CharExtensions
{
+ ///
+ /// Generates a new random string by filling it with characters found in .
+ ///
+ /// The character set.
+ /// The length of the string to generate.
+ /// Returns a containing characters.
+ public static string Random(this char[] chars, int length)
+ {
+ return chars.Random(length, new Random());
+ }
+
+ ///
+ /// Generates a new random string by filling it with characters found in .
+ ///
+ /// The character set.
+ /// The length of the string to generate.
+ /// The instance.
+ /// Returns a containing characters.
+ public static string Random(this char[] chars, int length, Random random)
+ {
+ StringBuilder builder = new StringBuilder(length);
+ for (int i = 0; i < length; i++)
+ {
+ builder.Append(chars.ElementAt(random.Next(0, chars.Length)));
+ }
+
+ return builder.ToString();
+ }
+
+ ///
+ /// Generates a new random string by filling it with characters found in .
+ ///
+ /// The character set.
+ /// The length of the string to generate.
+ /// Returns a containing characters.
+ public static string Random(this IEnumerable chars, int length)
+ {
+ return chars.Random(length, new Random());
+ }
+
+ ///
+ /// Generates a new random string by filling it with characters found in .
+ ///
+ /// The character set.
+ /// The length of the string to generate.
+ /// The instance.
+ /// Returns a containing characters.
+ public static string Random(this IEnumerable chars, int length, Random random)
+ {
+ return chars.ToArray().Random(length, random);
+ }
+
///
/// Repeats a character a specified number of times.
///
diff --git a/X10D/src/StringExtensions.cs b/X10D/src/StringExtensions.cs
index ea2e50e..71a9025 100644
--- a/X10D/src/StringExtensions.cs
+++ b/X10D/src/StringExtensions.cs
@@ -108,6 +108,29 @@
return encoding.GetBytes(str);
}
+ ///
+ /// Generates a new random string by filling it with characters found in .
+ ///
+ /// The character set.
+ /// The length of the string to generate.
+ /// Returns a containing characters.
+ public static string Random(this string str, int length)
+ {
+ return str.Random(length, new Random());
+ }
+
+ ///
+ /// Generates a new random string by filling it with characters found in .
+ ///
+ /// The character set.
+ /// The length of the string to generate.
+ /// The instance.
+ /// Returns a containing characters.
+ public static string Random(this string str, int length, Random random)
+ {
+ return str.ToCharArray().Random(length, random);
+ }
+
///
/// Repeats a string a specified number of times.
///