Example #1
0
        /// <summary>
        /// 产生随机数字码
        /// </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);
        }
Example #2
0
 /// <summary>
 /// 返回指定范围内的随机整数
 /// </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));
 }