Essential C# Generating Random Numbers  Suggest an edit

Generating the same sequence of random numbers over and over again

When creating Random instances with the same seed, the same numbers will be generated.

int seed = 5;
for (int i = 0; i < 2; i++)
{
   Console.WriteLine("Random instance " + i);
   Random rnd = new Random(seed);
   for (int j = 0; j < 5; j++)
   {
      Console.Write(rnd.Next());
      Console.Write(" ");
   }

   Console.WriteLine();
}

Output:

Random instance 0
726643700 610783965 564707973 1342984399 995276750
Random instance 1
726643700 610783965 564707973 1342984399 995276750


Table Of Contents
22 Enum
25 GUID
107 Stream
108 Timers
145 Generating Random Numbers
  ↑ ↓ to navigate     ↵ to select     Esc to close