Saturday, February 23, 2008

.NET: Generating a Random Number in C#

private int RandomNumber(int min, int max)
{
Random random = new Random();
return random.Next(min, max);
}

Copy the above code in your class where you want to use it and call like this:

int returnValue = RandomNumber(5, 20);

No comments: