开发者

Random Pick 2 Int as an option

开发者 https://www.devze.com 2023-03-09 06:59 出处:网络
private void btnStart_Click(object sender, EventArgs e) { Random random = new Random(); int randomNumber = random.Next(0, 1000);
private void btnStart_Click(object sender, EventArgs e)
{
    Random random = new Random();
    int randomNumber = random.Next(0, 1000);
    int RandomTolerance = 5 || 10;
    lblRandomValue.Text = randomNumber + "000" + "O" + RandomTolerance;
}

I do not understand how to allow the RandomT开发者_运维问答olerance to choose between 5 and 10 only as an integer.


int RandomTolerance=random.Next(0,2)<1?5:10;

As a side note, reseeding your random number generator over and over is usually a bad idea. You should read up on how random number generators work.


int RandomTolerance = random.Next(1,3) * 5;

Disclaimer: @Blindy, this sounded better :)

0

精彩评论

暂无评论...
验证码 换一张
取 消