2012年11月29日 星期四

generate ramdom list



using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {

            foreach (int tt in GenerateRandomList(1, 20))
            {
                Console.WriteLine(tt);
            }
            Console.ReadLine();
        }

        private static List GenerateRandomList(int min,int max)
        {
            Random rand = new Random();
            int index = 0;
            string str = string.Empty;
            List list = new List();
            List randList = new List();

            for (int j = min; j <= max; j++)
            {
                list.Add(j);
            }

            for (int i = 0; i < max; i++)
            {
                index = rand.Next(0, list.Count - 1);
                randList.Add (list[index]);
                list.RemoveAt(index);
            }
            return randList ;
        }
    }
}

沒有留言: