自定义生成随机数(同一时间内不重复)

private static char[] constant =  
      {  
        '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','V','W','X','Y','Z'  
      };
    //随机数长度
        public static string GenerateRandomNumber(int Length)
        {
            System.Text.StringBuilder newRandom = new System.Text.StringBuilder(36);
            Random rd = new Random(Guid.NewGuid().GetHashCode());
            for (int i = 0; i < Length; i++)
            {
                newRandom.Append(constant[rd.Next(36)]);
            }
            return newRandom.ToString();
        }

 

posted @ 2017-04-25 09:50  怪先生  阅读(1831)  评论(0编辑  收藏  举报