using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PreCLPZConsoleApp
{
class Program
{
static void Main(string[] args)
{
Program p = new Program();
for (int i = 0; i < 100; i++ )
{
Console.WriteLine(p.GetRandomCode(10));
Console.ReadKey();
}
}
/// <summary>
/// 随机产生验证码
/// </summary>
/// <param name="CodeCount">验证符个数</param>
/// <returns></returns>
private string GetRandomCode(int CodeCount)
{
string allChar = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,M,N,P,Q,R,S,T,U,W,X,Y,Z";
string[] allCharArray = allChar.Split(',');
int allCharLength = allCharArray.Length;
string resultCode = "";
Random rd = new Random();
//依次随机取出一个符号
for (int i = 0; i < CodeCount; i++)
{
int random = rd.Next(allCharLength - 1);
string oneChar = allCharArray[random];
resultCode += oneChar;
}
return resultCode;
}
}
}
产生随机验证码(控制台)
最新推荐文章于 2019-07-19 14:18:35 发布