码迷,mamicode.com
首页 > 其他好文 > 详细

生成日期随机码

时间:2016-05-15 10:52:24      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:

public static string GetRamCode(int codeCount)
        {
            #region
            return DateTime.Now.ToString("CGyyyyMMddHHmmssffff");
            string allChar = "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,W,X,Y,Z,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";
            string[] allCharArray = allChar.Split(‘,‘);
            string randomCode = "";
            int temp = -1;
            Random rand = new Random();
            for (int i = 0; i < codeCount; i++)
            {
                if (temp != -1)
                {
                    rand = new Random(i * temp * ((int)DateTime.Now.Ticks));
                }
                int t = rand.Next(61);
                if (temp == t)
                {
                    return GetRamCode(codeCount);
                }
                temp = t;
                randomCode += allCharArray[t];
            }
            return randomCode;
            #endregion
        }

生成日期随机码

标签:

原文地址:http://www.cnblogs.com/ysz12300/p/5494744.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!