Beispiel #1
0
 /// <summary>
 ///     Generates a random string of the specified length, taking characters from the specified arsenal of characters.</summary>
 /// <param name="length">
 ///     Length of the string to generate.</param>
 /// <param name="takeCharactersFrom">
 ///     Arsenal to take random characters from. (Default is upper- and lower-case letters and digits.)</param>
 /// <param name="rnd">
 ///     If not <c>null</c>, uses the specified random number generator.</param>
 public static string GenerateString(int length, string takeCharactersFrom = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", Random rnd = null)
 {
     if (takeCharactersFrom == null)
     {
         throw new ArgumentNullException(nameof(takeCharactersFrom));
     }
     return(new string(Ut.NewArray(length, i => takeCharactersFrom[rnd == null ? Rnd.Next(takeCharactersFrom.Length) : rnd.Next(takeCharactersFrom.Length)])));
 }