c#用一个按钮在5个label中产生不同随机数,怎么实现。
2个回答
展开全部
按钮事件方法中:
Random ra = new Random(); //产生随机数
label1.Text = ra.Next().ToString(); //给各个label标签赋值
label2.Text = ra.Next().ToString();
label3.Text = ra.Next().ToString();
label4.Text = ra.Next().ToString();
label5.Text = ra.Next().ToString();
Random ra = new Random(); //产生随机数
label1.Text = ra.Next().ToString(); //给各个label标签赋值
label2.Text = ra.Next().ToString();
label3.Text = ra.Next().ToString();
label4.Text = ra.Next().ToString();
label5.Text = ra.Next().ToString();
展开全部
private void button1_Click(object sender, EventArgs e)
{
Random r1 = new Random();
int r11 = r1.Next(0, 100);
int r22 = r1.Next(0, 900);
int r33 = r1.Next(0, 50);
int r44 = r1.Next(0, 400);
int r55 = r1.Next(0, 120);
label1.Text = r1.Next(0,100).ToString();
label2.Text = r1.Next(0, 900).ToString();
label3.Text = r1.Next(0, 50).ToString();
label4 .Text = r1.Next(0, 400).ToString();
label5 .Text = r1.Next(0, 120).ToString();
}
最重要就是NEXT后面的取值范围要不一样!
{
Random r1 = new Random();
int r11 = r1.Next(0, 100);
int r22 = r1.Next(0, 900);
int r33 = r1.Next(0, 50);
int r44 = r1.Next(0, 400);
int r55 = r1.Next(0, 120);
label1.Text = r1.Next(0,100).ToString();
label2.Text = r1.Next(0, 900).ToString();
label3.Text = r1.Next(0, 50).ToString();
label4 .Text = r1.Next(0, 400).ToString();
label5 .Text = r1.Next(0, 120).ToString();
}
最重要就是NEXT后面的取值范围要不一样!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询