Generate Random within a range - CSharp System

CSharp examples for System:Random

Description

Generate Random within a range

Demo Code


using System.IO;/*from   w  w  w  .j  a v  a 2 s  .c o  m*/
using System.Collections;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;

public class Main{

        public static int GenerateRandom(int minValue, int maxValue)
        {
            if (minValue <= maxValue)
            {
                Random random = new Random();
                return random.Next(minValue, maxValue);
            }
            else
            {
                return 0;
            }
        }
}

Related Tutorials