最近在跑抽奖论坛,论坛中有很多大牛发布自动抽奖的工具,让我这个靠编程吃饭的人感到很是惭愧,也想自己写个可是一点头绪都没有,csdn的大牛们有写过的没?

解决方案 »

  1.   

    参考using System;
    using System.Collections.Generic;
    using System.Text;namespace ConsoleApplication1
    {
        class Program
        {
            static
    void Main(string[] args)
            {
                List<List<int>> TValues =
    new List<List<int>>();
                List<int> TFirst = GetValue(30, null);//获得30个随机数泛型集合
                TValues.Add(TFirst);
                List<int> TSecond = GetValue(10, TValues);//获得10个随机数泛型集合
                TValues.Add(TSecond);
                List<int> TThird = GetValue(5, TValues);//获得5个随机数泛型集合            Console.WriteLine("30个数:"
    + GetString(TFirst));
                Console.WriteLine("10个数:"
    + GetString(TSecond));
                Console.WriteLine("5个数:"
    + GetString(TThird));
            }        private
    static List<int> GetValue(int count, List<List<int>> TValues)
            {
                List<int> TValue =
    new List<int>();
                Random random =
    new Random();
                int i =
    0;
                int value =
    0;
                while (i < count)
                {
                    bool bExist =
    false;
                    value = random.Next(1, 5001);
                    if (TValues !=
    null)
                    {
                        foreach (List<int> Ttmp in TValues)
                        {
                            if (Ttmp.Contains(value))
                            {
                                bExist =
    true;
                                break;
                            }
                        }
                    }
                    if (!bExist)
                    {
                        if (!TValue.Contains(value))
                        {
                            TValue.Add(value);
                            i++;
                        }
                    }
                }
                return TValue;
            }        private
    static
    string GetString(List<int> T)
            {
                string back =
    "";
                foreach (int value in T)
                {
                    if (back ==
    "")
                        back = value.ToString();
                    else
                        back +=
    ","
    + value.ToString();
                }
                return back;
            }
        }
    }
      

  2.   

    http://topic.csdn.net/u/20101215/20/e83c4246-3903-4e32-97c4-8fc2a386c8f4.html