public static string GenerateCheckCode(VALIDATE_CODE_TYPE type, int len) { char[] VALIDATE_CODE_CHARACTERS = { '2', '3', '4', '5', '6', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'W', 'X', 'Y' }; char code; string checkCode = String.Empty; System.Random random = new Random(); for (int i = 0; i < len; i++) { code = VALIDATE_CODE_CHARACTERS[random.Next(VALIDATE_CODE_CHARACTERS.Length)]; if (type == VALIDATE_CODE_TYPE.NUMBER) { if ((int)code < 48 || (int)code > 57) { i--; continue; } } else if (type == VALIDATE_CODE_TYPE.CHARACTER) { if ((int)code < 65 || (int)code > 90) { i--; continue; } } checkCode += code; } return(checkCode.ToLower()); }
public static string GenerateCheckCode(VALIDATE_CODE_TYPE type, int len) { char[] VALIDATE_CODE_CHARACTERS = { '2', '3', '4', '5', '6', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'W', 'X', 'Y' }; char code; string checkCode = String.Empty; System.Random random = new Random(); for (int i = 0; i < len; i++) { code = VALIDATE_CODE_CHARACTERS[random.Next(VALIDATE_CODE_CHARACTERS.Length)]; if (type == VALIDATE_CODE_TYPE.NUMBER) { if ((int)code < 48 || (int)code > 57) { i--; continue; } } else if (type == VALIDATE_CODE_TYPE.CHARACTER) { if ((int)code < 65 || (int)code > 90) { i--; continue; } } checkCode += code; } return checkCode.ToLower(); }