C # generate random strings,
1. The code is reprinted. Record it here.
/// <Summary> /// generate a random string /// </summary> /// <param name = "length"> length of the target string </param> // /<param name = "useNum"> whether it contains numbers, 1 = include. The default value is include </param> // <param name = "useLow"> whether to include lowercase letters, 1 = include, the default value is include </param> /// <param name = "useUpp"> whether to include uppercase letters, 1 = include, the default value is include </param> /// <param name = "useSpe"> whether it contains special characters, 1 = include, the default value is </param> /// <param name = "custom">, enter the list of characters to be included </param> // <returns> A random string of the specified length </returns> public static string GetRan DomString (int length, bool useNum, bool useLow, bool useUpp, bool useSpe, string custom) {byte [] B = new byte [4]; new System. security. cryptography. RNGCryptoServiceProvider (). getBytes (B); Random r = new Random (BitConverter. toInt32 (B, 0); string s = null, str = custom; if (useNum = true) {str + = "0123456789" ;}if (useLow = true) {str + = "abcdefghijklmnopqrstuvwxyz";} if (useUpp = true) {st R + = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";} if (useSpe = true) {str + = "! \ "# $ % & '() * +,-./:; <=>? @ [\] ^ _ '{| }~ ";}For (int I = 0; I <length; I ++) {s + = str. substring (r. next (0, str. length-1), 1);} return s ;}