Posted by : Anwar Hossain
Category : c # basic tutorial

How to generate random number in c #

In this tutorial I will show how to generate random number in C# programming language. We have to use Random Class to generate Ran Random number. Next Method of Random class is used to generate random number. In this example I have used two argument fist argument takes min number and second argument takes max number. I have given another example to generate random number using loop and it will also give you clear idea about Random number generation in c sharp.

Generate random number in c# prgramming


Simple random  number in C Sharp

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;


namespace randomnumber


    class Program


        static void Main(string[] args)



            // simple random number.


             Random r = new Random();


             Console.WriteLine("\nsimple random number generation  :{0}", r.Next(25, 1000));





            int[] randomNum = new int[10];

            Random RandomNumber = new Random();



            for (int i = 0; i < 10; i++)


                randomNum[i] = RandomNumber.Next(1, 10);




            foreach (int j in randomNum)


                Console.WriteLine("Random number using loop :{0}", j);











Out Put


Realted Article Headline

How to find odd number in c #
How to generate random number in c #
Nested For Loop Example in C Sharp
Store C sharp reference type in a List C#
Find number of items in a List C#
Concept about C # List
Custom Time formatting example C #
Custom Date formatting example C #
String Format Example using ASP.Net C#
Simple enum example in C Sharp
Nested switch-case statement example in C #
Combined statement example in C #
C Sharp switch case statement Example
C# SUM ArrayList Element Example
C# String Class Methods Example
C Sharp String Class Properties and Methods
C Sharp String Class Example
How to join two ArrayList collections in C#.
How to Use C Sharp Math Class
C Sharp ArrayList Property and Method
C Sharp ArrayList Example
C Sharp Arrays Example
C Sharp Logical operator Example
C Sharp Relational operators
C Sharp Arithmetic operators Example
C Sharp Common Assignment Operator
Simple for loop example in c sharp

Article Category

How to create control dynamically
Learn HTML for beginner
DataList example in C Sharp
Mail sending in c#
State Management in ASP C #
Basic sql tutorial for Beginner
DataTable example in ASP.Net C#
How to use LINQ in ASP.NET C# c # basic tutorial
How to use ajax toolkit in C#
How to use different types of validation control using c#
How to use grid view in c#
Protected by Copyscape Online Plagiarism Detection