产生一百个不重复的随机数

int[] intArr = new int[100];
            ArrayList myList = new ArrayList();
            Random rnd = new Random();
            while(myList.Count<100)
            {
                int num = rnd.Next(1,101);
                if(!myList.Contains(num))
                {
                    myList.Add(num);
                }
            }
            for (int i = 0; i < 100;i++ )
            {
                intArr[i] = (int)myList[i];
                if (i < 99)
                {
                    Console.Write("{0},", intArr[i]);
                }
                else
                {
                    Console.WriteLine(intArr[i]);
                }
            }
            Console.WriteLine();
            myList.Sort();
            for (int i = 0; i < 100;i++ )
            {
                if (i < 99)
                {
                    Console.Write("{0},", myList[i]);
                }
                else
                {
                    Console.WriteLine(myList[i]);
                }
            }
            Console.ReadKey();

https://item.taobao.com/item.htm?id=520079775428

posted @ 2014-01-03 11:43  风末之路  阅读(201)  评论(0编辑  收藏  举报