產生隨機數

  protected string CreateRandomCode(int codeCount)
    {
        string allChar = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,P,Q,R,S,T,U,W,X,Y,Z";
        string[] allCharArray = allChar.Split(',');
        string randomCode = "";
        int temp = -1;
        Random random = new Random();
        for (int i = 0; i < codeCount; i++)
        {
            if (temp != -1)
            {
                random = new Random(i * temp * (int)DateTime.Now.Ticks);
            } int t = random.Next(23);
            if (temp == t)
            {
                return CreateRandomCode(codeCount);
            }
            temp = t;
            randomCode += allCharArray[temp];
        }
        return randomCode;
    }

 

posted @ 2013-02-04 16:56  sirili  阅读(162)  评论(0编辑  收藏  举报