Introduction
In this article I have explained the C# Random function which is used in an ASP.Net application so let us start with the basics to ensure this article is understandable for beginners too.
What is Random Number?
A number that has no specific sequence which is changed dynamically with the given range in the Random function each time it is generated is called a Random number.
So I hope you understand the concept of random numbers. Now we will create the application for demonstrating the use of the Random function.
Now let us start to create a Website as:
- Start - All Programs - Microsoft Visual Studio 2010.
- File - New Website - C# - Empty website (to avoid adding a master page).
- Give the web site a name such as Generate_RandomNumbres or another as you wish and specify the location.
- Then right-click on Solution Explorer - Add New Item - Default.aspx page.
- Drag and drop one button to generate a random number and one label to show the generated random numbers in the <form> section of the Default aspx page.
<formid="form1"runat="server">
<asp:Button id ="Button1" runat ="server"Text="Generate number " onclick="Button1_Click" />
<p>
<asp:Label id ="Label1"runat ="server" Text ="Label"></asp:Label></p>
</ form >
</ form >



Girish SharmaPosted Jul 13, 2021, 3:06 AM
What if I wish to display random number after every one second automatically.
Vithal WadjePosted May 14, 2015, 9:05 AM
duplicate as wel ,in current request it will not be return any duplicate but when new request start its possibility to return duplicate value within that given range . to avoid this and if you are trying to generate unique password then try asp.net membership provider class to generate unique password that is Membership.GeneratePassword(8, 1) which takes two parameter password length and number of alphanumerical .
Joel PrabhuPosted May 14, 2015, 1:46 AM
random number return only unique or it will return duplicate also.
Vithal WadjePosted Dec 5, 2014, 12:09 AM
thanks Gowtham Ravi sir
Vithal WadjePosted Dec 5, 2014, 12:08 AM
thanks vinay singh sir
Gowtham RaviPosted Dec 3, 2014, 1:20 PM
nice one
Former memberPosted Oct 9, 2013, 7:30 AM
This is really cool article. have a look of this article and let me know your view
Vithal WadjePosted May 29, 2013, 3:57 PM
i dont know about that Ramesh,but ig you know then you can implement it in our own way,thanks for reading
Ramesh RPosted May 28, 2013, 5:30 PM
Why You are used for loop in above code..it will execute without using for LOOP..
Vithal WadjeeditedPosted Nov 1, 2012, 12:16 AMEdited Nov 1, 2012, 12:17 AM
thanks Rohatash sir,i will keep it in future
Rohatash KumareditedPosted Oct 31, 2012, 11:41 PMEdited Oct 31, 2012, 11:56 PM
Nice article Vithal. Keep it up