In ASP.Net 2.0 you can use Random class to generate the random numbers. Create an instance to an object of Random class and generate random numbers.
E.g.:
Random rand = new Random(); rand.Next(0, 10);
In the above rand is an object of Random Class. In the function Rand.Next, 2 parameters can be passed.
Next (int MinValue, int MaxValue)
MinValue: The inclusive lower bound of the random number generated.
MaxValue: The exclusive upper bound of the random number generated. It should be equal or greater than the MinValue.
Try the following C# code in ASP.Net web page to generate random numbers:
Random rand = new Random();
Response.Write(rand.Next(0, 10));
Every time you will run the page you will get random output digit.
See Also:
ASP.Net 2.0 Random Password Generator
Be the first to rate this post
Tags: asp.net 2.0, random class, random numbers, c#, free source code
5/22/2008 9:16:25 AM
Thanks for the tip.. Just used it
Lee
9/27/2008 1:29:53 AM
Very useful article. Cheers!!! Ujjwal B Soni
ujjwal b soni
10/11/2008 3:33:56 AM