產生隨機數

  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;
    }
原文地址:https://www.cnblogs.com/siri/p/2892036.html