2 Int random selection as an option

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 RandomTolerancechoosing between 5 and 10 only as an integer.

+3
source share
2 answers
int RandomTolerance=random.Next(0,2)<1?5:10;

As a side note, reusing a random number generator over and over is usually bad. You should read how random number generators work.

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

Disclaimer: @Blindy, that sounds better :)

+2
source

All Articles