日期:2014-05-17  浏览次数:20823 次

抽奖算法T_T,排除抽过的数字
写了个简单的抽奖功能,但是发现会抽取到重复数字,如何做才好?


       private void btn_start_Click(object sender, EventArgs e)
        {
            //开始抽奖
            if (btn_start.Text == "停止")
            {
                timer1.Stop();
                btn_start.Text = "开始";

                //保存获奖信息
                SaveResult();
            }
            else
            {
                cjnum++;
                timer1.Start(); 
                
            }

        }

        private void SaveResult()
        {
            TGH.Lib.Log.WriteFile(Application.StartupPath + "\\choujiang.txt", "第" + cjnum.ToString() + "次抽奖数为:" + lbl_num.Text);
            lbl_result.Text += "第" + cjnum.ToString() + "次抽奖号码为:" + lbl_num.Text;// +"\r\n";
        }

        public int[] getRandomNum(int num, int minValue, int maxValue)
        {
            Random ra = new Random(unchecked((int)DateTime.Now.Ticks));
            arrNum = new int[num];
            int tmp = 0;
            for (int i = 0; i <= num - 1; i++)