Wednesday, 14 May 2014

Random Number Generator C#

5/14/2014 - By Pranav Singh 0

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
  //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



Tags: , ,
About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top