The random number generation starts from a seed value. If the same seed is used repeatedly, the same series of numbers is generated. One way to produce different sequences is to make the seed value time-dependent, thereby producing a different series with each new instance of Random. By default, the parameterless constructor of the Random class uses the system clock to generate its seed value, while its parameterized constructor can take an Int32 value based on the number of ticks in the current time. However, because the clock has finite resolution, using the parameterless constructor to create different Random objects in close succession creates random number generators that produce identical sequences of random numbers.
Seed is a number used to calculate a starting value for the pseudo-random number sequence. If a negative number is specified, the absolute value of the number is used.
using System;
using System.Data.SqlClient;
namespace Test
{
class Program
{
private static Random r = new Random(25);
static void Main(string[] args)
{
Console.WriteLine(randomNo());
Console.WriteLine(randomNo());
Console.WriteLine(randomNo());
Console.WriteLine(randomNo());
Console.WriteLine(randomNo());
Console.WriteLine(randomNo());
Console.WriteLine(randomNo());
Console.WriteLine(randomNo());
Console.ReadLine();
}
private static int randomNo()
{
int n = r.Next(56);
return n;
}
}
}