首页 > 编程 > C# > 正文

C#生成不重复随机数列表实例

2020-01-24 03:35:24
字体:
来源:转载
供稿:网友

复制代码 代码如下:

/// <summary>
        /// 生成不重复随机数列表实例
        /// </summary>
        /// <param name="count">不重复数数量</param>
        /// <returns>不重复数列表</returns>
        private static List<int> GetRandomList(int count)
        {
            List<int> list = new List<int>();
            int num = 0;
            Random rnd = new Random();
            for (int i = 0; i < count; i++)
            {
                do
                {
                    num = rnd.Next(010000, 1000000);
                } while (list.Contains(num));//               
                list.Add(num);
            }
            return list;
        }

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表