How do I generate a random integer in C#?
Try these simple steps to create random numbers:
Create function:
private int randomnumber(int min, int max)
{
Random rnum = new Random();
return rnum.Next(min, max);
}
Use the above function in a location where you want to use random numbers. Suppose you want to use it in a text box.
textBox1.Text = randomnumber(0, 999).ToString();
0 is min and 999 is max. You can change the values to whatever you want.