ASP.Net Random Numbers

by top54u.com 06 Mar, 2008

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

Spotlight.....

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , , , ,

Comments

5/22/2008 9:16:25 AM

Lee

Thanks for the tip.. Just used it

Lee gb

9/27/2008 1:29:53 AM

ujjwal b soni

Very useful article.

Cheers!!!

Ujjwal B Soni

ujjwal b soni in

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

10/11/2008 3:33:56 AM




related videos.....
recent posts.....
top54u ezines.....