生成指定位数的随机数

来源:互联网 发布:和血滴子类似的淘宝 编辑:程序博客网 时间:2024/04/29 22:22
        public static string RandCode(int n)
        {
            
char[] arrChar = new char[]{           
           
'0','1','2','3','4','5','6','7','8','9',
           
'A','B','C','D','E','F','G','H','I','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z'
          };
            StringBuilder num 
= new StringBuilder();
            Random rnd 
= new Random(DateTime.Now.Millisecond);
            
for (int i = 0; i < n; i++)
            {
                num.Append(arrChar[rnd.Next(
0, arrChar.Length)].ToString());
            }
            
return num.ToString();
        }