随机产生不重复的数字

    public void ShowRandomNum()
    {
            ArrayList list = new ArrayList();
            Random rand = new Random();
            for (int i = 0; i < 5; i++)
            {
                while (true)
                {
                    int temp = rand.Next(0, 10);
                    if (!list.Contains(temp))
                    {
                        list.Add(temp);
                        break;
                    }
                    Thread.Sleep(50);
                }
            }
    }

 

posted @ 2013-02-19 15:21  Marble  阅读(147)  评论(0编辑  收藏