日期:2014-05-18 浏览次数:20912 次
using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; using System.Management; namespace ConsoleApplication { class Program { static void Main(string[] args) { int[] range = new int[33]; for (int i = 0; i < 33; i++)//初始化范围集合,从1到33 { range[i] = i + 1; } int[] result = CreateNumbers(range, 6); for(int i=0;i<result.Length;i++) { Console.WriteLine("result[{0}]={1}", i, result[i]); } Console.ReadKey(); } //取出不重复的6个数 static int[] CreateNumbers(int[] range, int count) { int[] result = new int[count]; Random random=new Random(); int index = 0; int temp = 0; for (int i = 0; i < count; i++) { index=random.Next() % (range.Length-i); result[i] = range[index]; //将当前已使用过的数移至集合末尾,并且将末尾原来没有使用的数放到当前位置 temp = range[range.Length - 1-i]; range[range.Length - 1-i] = range[index]; range[index]=temp; } return result; } } }
------解决方案--------------------
//拉一个Timer控件到窗体 Random rnd=new Random(unchecked((int)DateTime.Now.Ticks));//声明一个全局变量 private void timer1_Tick(object sender, System.EventArgs e)//添加Timer的Tick事件 { this.label1.Text=rnd.Next(1,39).ToString(); } private void btnStart_Click(object sender, System.EventArgs e)//开始按钮 { this.timer1.Start(); } private void btnEnd_Click(object sender, System.EventArgs e)//结束按钮 { this.timer1.Stop(); }
------解决方案--------------------
mark
------解决方案--------------------
很久很久以前做的一个双色球,拿出主要的给你看看,现在怎么这么多爱发两个一模一样帖子的啊
private void timer2_Tick(object sender, System.EventArgs e) { Random a=new Random(); int i1=a.Next(1,33); if(i1<10) { this.textBox1.Text="0"+i1.ToString(); } else { this.textBox1.Text=i1.ToString(); } int i2=a.Next(1,33); if(i2<10) { this.textBox2.Text="0"+i2.ToString(); } else { this.textBox2.Text=i2.ToString(); } int i3=a.Next(1,33); if(i3<10) { this.textBox3.Text="0"+i3.ToString(); } else { this.textBox3.Text=i3.ToString(); } int i4=a.Next(1,33); if(i4<10) { this.textBox4