Hello,

I am trying to program a random generator for some text, but facing a strange issue. I assumed that a random number will be generated each time the programm is running through the loop. But everytime the loop is repeated the same results (an so the same random numbers have been chosen?) appear. Also if the length of the arrays is identical, the same random number is used.

Can anyone give me a hint, how to

  1. I achieve that the random values will change for each instance the loop is running.
  2. achieve that different random values are chosen, also if two or more arrays have the same length


Thank you for help!

See code below:

Code:
 string[] jn1 = { "a1", "b1", "c1", "d1", "e1", "f1" };
            string[] jn2 = { "a2", "b2", "c2" };
            string[] jn3 = { "a3", "b3", "c3", "c4" };

            int anzahljns1 = jn1.Length;
            int anzahljns2 = jn2.Length;
            int anzahljns3 = jn3.Length;

            do
            {
                Random zufallszahl1 = new Random(0);
                Random zufallszahl2 = new Random(0);
                Random zufallszahl3 = new Random(0);

                int jpo1 = zufallszahl1.Next(0, anzahljns1);
                int jpo2 = zufallszahl2.Next(0, anzahljns2);
                int jpo3 = zufallszahl3.Next(0, anzahljns3);

                string first = jn1[jpo1];
                string second = jn2[jpo2];
                string third = jn3[jpo3];

                Console.WriteLine(first + " "+ second + " " + third);

                Console.WriteLine("...");
                repeat = Console.ReadLine();

            } while (repeat == "y");