Public classRand {/// <summary> ///Generate random numbers/// </summary> /// <param name= "Length" >Build Length</param> /// <returns></returns> Public Static stringNumber (intLength) { returnNumber (Length,false); } /// <summary> ///Generate random numbers/// </summary> /// <param name= "Length" >Build Length</param> /// <param name= "Sleep" >whether to block the current thread before the build to avoid duplication</param> /// <returns></returns> Public Static stringNumber (intLength,BOOLSleep) { if(Sleep) System.Threading.Thread.Sleep (3); stringresult =""; System.Random Random=NewRandom (); for(inti =0; i < Length; i++) {result+ = random. Next (Ten). ToString (); } returnresult; } /// <summary> ///generate random letters and numbers/// </summary> /// <param name= "Intstr" >Build Length</param> /// <returns></returns> Public Static stringSTR (intLength) { returnSTR (Length,false); } /// <summary> ///generate random letters and numbers/// </summary> /// <param name= "Length" >Build Length</param> /// <param name= "Sleep" >whether to block the current thread before the build to avoid duplication</param> /// <returns></returns> Public Static stringSTR (intLength,BOOLSleep) { if(Sleep) System.Threading.Thread.Sleep (3); Char[] Pattern =New Char[] {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' }; stringresult =""; intn =pattern.length; System.Random Random=NewRandom (~unchecked((int) (DateTime.Now.Ticks)) ; for(inti =0; i < Length; i++) { intRnd = random. Next (0, N); Result+=Pattern[rnd]; } returnresult; } /// <summary> ///generate random Pure letter random numbers/// </summary> /// <param name= "Intstr" >Build Length</param> /// <returns></returns> Public Static stringStr_char (intLength) { returnStr_char (Length,false); } /// <summary> ///generate random Pure letter random numbers/// </summary> /// <param name= "Length" >Build Length</param> /// <param name= "Sleep" >whether to block the current thread before the build to avoid duplication</param> /// <returns></returns> Public Static stringStr_char (intLength,BOOLSleep) { if(Sleep) System.Threading.Thread.Sleep (3); Char[] Pattern =New Char[] {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' }; stringresult =""; intn =pattern.length; System.Random Random=NewRandom (~unchecked((int) (DateTime.Now.Ticks)) ; for(inti =0; i < Length; i++) { intRnd = random. Next (0, N); Result+=Pattern[rnd]; } returnresult; } }
C # generates random numbers or random letters