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

复制代码 代码如下:

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

        /// 不重复数数量
        /// 不重复数列表
        private static List GetRandomList(int count)
        {
            List list = new List();
            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;
        }

你可能感兴趣的:(C#生成不重复随机数列表实例)