// The main functions of the random string generator are as follows:
// 1. Supports custom String Length
// 2. Support for custom numbers or not
// 3. You can customize whether the bucket contains lowercase letters.
// 4. Whether or not the User-Defined uppercase letters are supported
// 5. Support for custom symbols
// 6. Support for custom character sets
/// <Summary>
/// Generate a random string
/// </Summary>
/// <Param name = "length"> length of the target string </param>
/// <Param name = "useNum"> whether to include a number; 1 = include; default value: Include </param>
/// <Param name = "useLow"> whether it contains lowercase letters; 1 = contained; default value: Include </param>
/// <Param name = "useUpp"> whether to include uppercase letters, 1 = include, default: Include </param>
/// <Param name = "useSpe"> whether it contains special characters; 1 = contained; not included by default </param>
/// <Param name = "custom"> enter a list of custom characters to include. </param>
/// <Returns> A random string of the specified length </returns>
Public string GetRnd (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) {str + = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ";}
If (useSpe = true) {str + = "! \ "# $ % & '() * +,-./:; <=>? @ [\] ^ _ '{| }~ ";}
For (int I = 0; I <length; I ++)
{
S + = str. Substring (r. Next (0, str. Length-1), 1 );
}
Return s;
}