Esempio n. 1
0
        /// <summary>
        /// Generate random digit code
        /// </summary>
        /// <param name="length">Length</param>
        /// <returns>Result string</returns>
        public static string GenerateRandomPassword(int length)
        {
            using var random = new SecureRandomNumberGenerator();
            const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

            return(new string(Enumerable.Repeat(chars, length)
                              .Select(s => s[random.Next(s.Length)]).ToArray()));
        }
Esempio n. 2
0
        /// <summary>
        /// Generate random digit code
        /// </summary>
        /// <param name="length">Length</param>
        /// <returns>Result string</returns>
        public static string GenerateRandomDigitCode(int length)
        {
            using var random = new SecureRandomNumberGenerator();
            var str = string.Empty;

            for (var i = 0; i < length; i++)
            {
                str = string.Concat(str, random.Next(10).ToString());
            }
            return(str);
        }
Esempio n. 3
0
 /// <summary>
 /// Returns an random integer number within a specified rage
 /// </summary>
 /// <param name="min">Minimum number</param>
 /// <param name="max">Maximum number</param>
 /// <returns>Result</returns>
 public static int GenerateRandomInteger(int min = 0, int max = int.MaxValue)
 {
     using var random = new SecureRandomNumberGenerator();
     return(random.Next(min, max));
 }