第1个回答 2009-06-25
private void btnOk_Click_1(object sender, EventArgs e)
{
Random r = new Random();
txt1.Text = (int)r.Next(1, 36) + "";
txt2.Text = (int)r.Next(1, 36) + "";
txt3.Text = (int)r.Next(1, 36) + "";
txt4.Text = (int)r.Next(1, 36) + "";
txt5.Text = (int)r.Next(1, 36) + "";
txt6.Text = (int)r.Next(1, 13) + "";
txt7.Text = (int)r.Next(1, 13) + "";
}
第2个回答 2009-06-26
楼主你因为一开始就把随机生成的放到数组里了,所以,当i=j的时候就goto到where那里了,就会地循环。可以改成for (int j = 0; j <i;j++ )
或者:
System.Random ran = new Random();
System.Collections.Generic.List<int> aa = new System.Collections.Generic.List<int>();
for (int i = 0; i <7; i++)
{
int xx=(int)ran.Next(0,36)+1;
bool bb = true;
while(aa.Contains(xx)){xx=(int)ran.Next(0,36)+1;}
aa.Add(xx);
}
textBox1.Text=arry[1]+"";
textBox2.Text = arry[2] + "";
textBox6.Text = arry[3] + "";
textBox4.Text = arry[4] + "";
textBox5.Text = arry[5] + "";
textBox6.Text = arry[6] + "";
textBox7.Text = arry[7] + "";
第3个回答 2009-06-25
改成下面这样就行了
private void button1_Click(object sender, EventArgs e)
{
Random ran = new Random();
List<int> arr = new List<int>();
for (int i = 0; i < 7; i++)
{
arr.Add(ran.Next(0, 36));
for (int j = 0; j < arr.Count - 1; j++)
{
if (arr[i] == arr[j])
{
arr.RemoveAt(i);
i--;
break;
}
}
}
foreach (int var in arr)
{
MessageBox.Show(var.ToString());
}
}
第4个回答 2020-05-13
这个都看不准,你买什么??