生成无重复的随机数

 #region 生成随机数
        /// <summary>
        /// 
        /// </summary>
        private static int iCount;
        /// <summary>
        /// 生成随机数
        /// </summary>
        /// <returns></returns>
        public static string GenerateRandomNumber()
        {
            System.Threading.Interlocked.Increment(ref iCount);
            Random rnd = new Random(Guid.NewGuid().GetHashCode());
            return iCount.ToString().PadRight(4, '0') + rnd.Next(1, 10000).ToString().PadLeft(4, '0');
        } 
        #endregion

 

posted @ 2018-05-09 16:19  SmilePastaLi  阅读(140)  评论(0编辑  收藏  举报