While while writing code in c# there must be some situation in which we need to generate the random number and use it in our application or program. So here i will give you an for generating random number using c# in your asp.net,windows application by using c# and Vb.net.
Some of my previous articles are as follows: How to show error message in c# windows application | How to show Error & Warning Message Box in .NET , How to implement windows authentication in asp.net mvc , How to create a Xml Document Programmatically Using C#.Net .
So for this article first we will create a class for generating the random number :
C#. Net
Some of my previous articles are as follows: How to show error message in c# windows application | How to show Error & Warning Message Box in .NET , How to implement windows authentication in asp.net mvc , How to create a Xml Document Programmatically Using C#.Net .
So for this article first we will create a class for generating the random number :
C#. Net
//Common function
to generate the random no
private
static int
RandomNumberGeneration(int minval, int maxval)
{
Random
randomno = new Random();
return
randomno.Next(minval, maxval);
}
|
VB.Net
'Common function to generate the random no
Private Shared Function RandomNumberGeneration(ByVal minval As Integer, ByVal
maxval As Integer)
As Integer
Dim
randomno As New
Random()
Return
randomno.[Next](minval, maxval)
End Function
|
Now we will see the complete code
C#.Net
//How to create a Xml Document Programmatically Using C#.Net
static
void Main(string[]
args)
{
int
_randomNo = RandomNumberGeneration(100, 1000);
Console.WriteLine("Max Value :100 & Min Value : 1000\n");
Console.WriteLine("Generated Random NO :" +
_randomNo.ToString());
Console.ReadLine();
}
//Common
function to generate the random no
private
static int
RandomNumberGeneration(int minval, int maxval)
{
Random
randomno = new Random();
return
randomno.Next(minval, maxval);
}
|
VB.Net
Private Shared Sub Main(ByVal args
As String())
Dim
_randomNo As Integer
= RandomNumberGeneration(100, 1000)
Console.WriteLine("Max Value :100 & Min Value : 1000"
& vbLf)
Console.WriteLine("Generated Random NO :" &
_randomNo.ToString())
Console.ReadLine()
End Sub
|
Now run the application
0 comments:
Please let me know your view