C#随机生成字符串

C#随机生成字符串 字符串长度由 num决定

 private string GenerateCheckCode(int num) 
        { 
            int number;
            char code; 
            string checkCode = String.Empty; 
            Random random = new Random(); 
            for (int i = 0; i < num; i++) 
            { number = random.Next(); 
                if (number % 2 == 0)                
                    code = (char)('0' + (char)(number % 10));
                else                
                    code = (char)('A' + (char)(number % 26));
                checkCode += code.ToString(); 
            } 
             
            return checkCode; 
        }


 

你可能感兴趣的:(C#随机生成字符串)