Linux教程網
C# 生成指定位數的隨機字符串:
- string getString(int count)
- {
- int number;
- string checkCode = String.Empty; //存放隨機碼的字符串
-
- System.Random random = new Random();
-
- for (int i = 0; i < count; i++) //產生4位校驗碼
- {
- number = random.Next();
- number = number % 36;
- if (number < 10)
- {
- number += 48; //數字0-9編碼在48-57
- }
- else
- {
- number += 55; //字母A-Z編碼在65-90
- }
-
- checkCode += ((char)number).ToString();
- }
- return checkCode;
- }
Copyright ©
Linux教程網 All Rights Reserved