c# 生成随机N位数字串(每位可以重复)

/// <summary>
        /// 生成随机数字窜
        /// </summary>
        /// <param name="Digit">位数</param>
        /// <returns></returns>
        private string RandomNum(int Digit)
        {
            StringBuilder sb = new StringBuilder();
            Random random = new Random();
            int Nums = Digit;
            while (Nums > 0)
            {
                int i = random.Next(1, 10);// 9>=a>=1
                if (sb.Length < Digit)
                {
                    sb.Append(i);
                }
                Nums -= 1;
            }
            return sb.ToString();
        }

 

posted @ 2014-09-12 11:07  沙漠绿洲uibe  阅读(287)  评论(0编辑  收藏  举报