how to generate random number in csharpIn this code snippet I will show you how to generate random number in csharp.
CSharp has a Random() class that generated random number between 2 numbers.
Code
public int GetRandomNumber(int min, int max)
{
Random random = new Random();
return random.Next(min, max);
}
The above function will generate a random number between min and max values supplied. To show random number I have called GetRandomNumber() in loop in ShowRandonNumber() method below.
public void ShowRandonNumber()
{
for (int count=0;count<5;count++)
Response.Write(GetRandomNumber(5, 20));
}
Enjoy coding...........