主题:这个随机数怎么改才能让他不重复?
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public static int roCount = 0;
public int getFormatedNumeric(int min, int max)
{
int num = 0;
Random ro = new Random(unchecked((int)DateTime.Now.Ticks * roCount));
num = ro.Next(min, max);
roCount++;
return num;
}
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
this.timer1.Enabled = true;
}
private void Form1_Load(object sender, EventArgs e)
{
Random r = new Random();
int i1 = r.Next(5);
}
private void timer1_Tick_1(object sender, EventArgs e)
{
int s1, s2, s3, s4, s5, s6, s7;
s1 = getFormatedNumeric(1, 33);
s2 = getFormatedNumeric(1, 33);
s3 = getFormatedNumeric(1, 33);
s4 = getFormatedNumeric(1, 33);
s5 = getFormatedNumeric(1, 33);
s6 = getFormatedNumeric(1, 33);
s7 = getFormatedNumeric(1, 16);
this.textBox1.Text = Convert.ToString(s1);
this.textBox2.Text = Convert.ToString(s2);
this.textBox3.Text = Convert.ToString(s3);
this.textBox4.Text = Convert.ToString(s4);
this.textBox5.Text = Convert.ToString(s5);
this.textBox6.Text = Convert.ToString(s6);
this.textBox7.Text = Convert.ToString(s7);
}
private void button2_Click(object sender, EventArgs e)
{
this.timer1.Enabled = false;
}
{
public partial class Form1 : Form
{
public static int roCount = 0;
public int getFormatedNumeric(int min, int max)
{
int num = 0;
Random ro = new Random(unchecked((int)DateTime.Now.Ticks * roCount));
num = ro.Next(min, max);
roCount++;
return num;
}
public Form1()
{
InitializeComponent();
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
this.timer1.Enabled = true;
}
private void Form1_Load(object sender, EventArgs e)
{
Random r = new Random();
int i1 = r.Next(5);
}
private void timer1_Tick_1(object sender, EventArgs e)
{
int s1, s2, s3, s4, s5, s6, s7;
s1 = getFormatedNumeric(1, 33);
s2 = getFormatedNumeric(1, 33);
s3 = getFormatedNumeric(1, 33);
s4 = getFormatedNumeric(1, 33);
s5 = getFormatedNumeric(1, 33);
s6 = getFormatedNumeric(1, 33);
s7 = getFormatedNumeric(1, 16);
this.textBox1.Text = Convert.ToString(s1);
this.textBox2.Text = Convert.ToString(s2);
this.textBox3.Text = Convert.ToString(s3);
this.textBox4.Text = Convert.ToString(s4);
this.textBox5.Text = Convert.ToString(s5);
this.textBox6.Text = Convert.ToString(s6);
this.textBox7.Text = Convert.ToString(s7);
}
private void button2_Click(object sender, EventArgs e)
{
this.timer1.Enabled = false;
}