翔如菲菲

其实天很蓝,阴云总会散;其实海不宽,此岸连彼岸.

导航

随机集合

class Program
    {
        static  Random r = new Random(0);
        static void Main(string[] args)
        {
            List<string> list = new List<string> { "0""1""2""3""4""5""6""7""8""9" };
            List<string> result;
            int count = 0;
            while (count++ < 20)
            {
                Console.WriteLine("第{0}次轮询", count);
                list = new List<string> { "0""1""2""3""4""5""6""7""8""9" };
                result = RadomList(list);
                foreach (var item in result)
                {
                    Console.Write(item+" ");
                }
                Console.WriteLine();
            }
            Console.Read();
        }

        private static List<string> RadomList(List<string> list)
        {
            List<string> result = new List<string>();
         
            while (list.Count > 0)
            {
                int data = r.Next(0, list.Count);
                result.Add(list[data]);
                list.RemoveAt(data);
            }
            // result.Add(list[0]);
            return result;
        }
    }

posted on 2011-12-06 13:01  翔如飞飞  阅读(191)  评论(0编辑  收藏  举报