Exemplo n.º 1
0
        /// <summary>
        /// Function that generates random string.
        /// </summary>
        /// <param name="minLen">Minimal length.</param>
        /// <param name="maxLen">Maximum length.</param>
        /// <param name="useDigit">Value that indicates if numbers are included.</param>
        /// <returns>String value.</returns>
        public static string GetRandStr(int minLen, int maxLen, bool useDigit = false)
        {
            string valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

            if (useDigit)
            {
                valid += "1234567890";
            }

            StringBuilder res    = new StringBuilder();
            int           length = R.GetInt32(minLen, maxLen + 1);

            for (int i = 0; i < length; i++)
            {
                res.Append(valid[R.GetInt32(valid.Length)]);
            }

            return(res.ToString());
        }