Seed Value

The Random class uses the seed value as a starting value for the pseudo-random number generation algorithm. By default, the Random class uses the system clock to generate its seed value so that each instance of the Random class can generate different random numbers.

Two different instances of the Random class having the same seed value will generate the same random numbers, as shown below.

Random random1 = new Random(10); // seed value 10
for (int i = 0; i < 4; i++){
    Console.WriteLine(random1.Next());
}

Random random2 = new Random(10); // seed value 10, the same as in the first
for (int i = 0; i < 4; i++){
    Console.WriteLine(random2.Next());
}

Comments

Leave a Comment

All fields are required. Your email address will not be published.