如何在数组中存储随机唯一编号 [英] How to store random unique no in array

查看:71
本文介绍了如何在数组中存储随机唯一编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我单击按钮时,我有三个文本框和一个按钮,然后在文本框中显示随机否.
如果文本框为5,则随机数为1到5.

I have three text box and one button when i click on the button then display random no in the textbox.
if text box is 5 then random is within 1 to 5.

推荐答案

private Random rand = new Random();
...
int max = int.Parse(myTextBox.Text);
int val = rand.Next(1, max+1);
myOtherTextBox.Text = val.ToString();



您可以使用Random类,这是一个示例:
Hi,
You can use Random class, here is a sample:
Random rand = new Random();
int rand1_5 = rand.Next(int.Parse(txt1.Text), int.Parse(txt2.Text));


为了保存随机数,可以将它们放入ArrayList


In order to save random numbers, you can put them in an ArrayList

ArrayList arr = new ArrayList();
arr.Add(rand1_5);


干杯


这篇关于如何在数组中存储随机唯一编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆