c#之双色球
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading; namespace 摇奖机程序 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } bool b = false; private void button1_Click(object sender, EventArgs e) { if (b == false) { b = true; int num = int.Parse(this.textBox1.Text); button1.Text = "停止"; Thread th = new Thread(PlayGame); th.IsBackground = true; th.Name = "新线程"; // th. th.Start(num); } else//b==true { b = false; button1.Text = "开始"; } //PlayGame(); } private void PlayGame(object ss) { Random r = new Random(); while (b) { listBox1.Items.Clear(); int num = (int)ss; for (int i = 0; i < num; i++) { //int[] nums = new int[6]; List<int> nums = new List<int>(); for (int j = 0; j < 6; j++) { int cu = r.Next(1, 34); if (nums.Contains(cu)) { j--; } else { nums.Add(cu); } } nums.Sort(); int lan=r.Next(1,17); string zu = nums[0].ToString() + " " + nums[1].ToString() + " " + nums[2].ToString() + " " + nums[3].ToString() + " " + nums[4].ToString() + " " + nums[5].ToString() + "-" + lan; listBox1.Items.Add(zu); } } } private void Form1_Load(object sender, EventArgs e) { Control.CheckForIllegalCrossThreadCalls = false; } } }