生成隨機字元串,字元組合等... ...
/// <summary> /// 隨機生成字元串 /// </summary> /// <param name="OperationType">數字字母組合:NUMBERLETTER 數字:NUMBER 大小寫組合字母:ALLLETTER 大寫字母:UPLETTER 小寫字母:LOWLETTER</param> /// <param name="Length">位數</param> /// <returns></returns> public static string CharM(string OperationType, int Length) { string chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; switch (OperationType) { case "NUMBERLETTER"://全字元模式 chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; break; case "NUMBER"://數字模式 chars = "0123456789"; break; case "ALLLETTER"://大小寫字母模式 chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; break; case "UPLETTER"://大寫字母模式 chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; break; case "LOWLETTER"://小寫字母模式 chars = "abcdefghijklmnopqrstuvwxyz"; break; } Random randrom = new Random((int)DateTime.Now.Ticks); string str = ""; for (int i = 0; i < Length; i++) { str += chars[randrom.Next(chars.Length)]; } return str; }
生成隨機字元串,字元組合等...