- ///
- /// 随机生成字符串
- ///
- ///
- public static string CreateRandomString(int length)
- {
- Random rand = new Random(DateTime.Now.Second);
- int number;
- char code;
- string checkCode = String.Empty;
- for (int i = 0; i < length; i++)
- { //随机产生一个整数
- number = rand.Next();
- //如果随机数是偶数 取余选择从[0-9]
- if (number % 2 == 0)
- code = (char)('0' + (char)(number % 10));
- else
- //如果随机数是奇数 选择从[A-Z]
- code = (char)('A' + (char)(number % 26));
- checkCode += code.ToString();
- }
- return checkCode;
- }