C#生成防伪码

1)防伪码的组成
防伪码由以下字符组成:0123456789ABCDEFGHJKLMNPQRSTUVWXYZ
(数字1和字母I相近、数字0和字母O相近,所以去掉字母I和字母O。全部字母大写) \
2)在命令行中输入2个参数,分别是:
防伪码长度
防伪码个数
例如:在命令行中调用程序为:学号.exe 10 10000
指的是防伪码长度为10,生成10000个防伪码。
3)防伪码的生成及注意事项
防伪码的长度由命令行参数决定;

所生成的防伪码不能重复(按照以上例子,生成了10000个防伪码,这10000个防伪码就肯定不能重复)。


  class Program
    {
        static string strTableChar = "0123456789ABCDEFGHJKLMNPQRSTUVWXYZ";
        static StringBuilder str=new StringBuilder();
        public static void random(int n,int length)
        {
            Random ra = new Random();
            HashSet<String> hashset = new HashSet<String>();
            while(hashset.Count<n)
            {
                for (int j = 0; j < length; j++)
                {
                    int a = ra.Next(33);
                    str.Append(strTableChar[a]);
                }
                hashset.Add(str.ToString());
                str.Clear();
            } 
        }

        public static void Main(string[] args)
        {
            int length = int.Parse(args[0]);
            int n = int.Parse(args[1]);
            Stopwatch timer1 = new Stopwatch();
            timer1.Start();
            random(n,length);
            timer1.Stop();
            double dMilliseconds = timer1.Elapsed.TotalMilliseconds;
            Console.WriteLine("生成个数为a:{0},运行时间为a:{1}",n,dMilliseconds);
            Console.ReadKey();
            Console.ReadLine();
        }
    }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值