|
-
September 14th, 2015, 02:17 AM
#1
No "real" random numbers when using loop
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
- I achieve that the random values will change for each instance the loop is running.
- 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");
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|