I have a simple method that opens a text file with a list of 10,000 words and generates a random string from those words. Here is the method:
private string GetWords()
string sentence = "";
for (int y = 0; y < 10; y++)
r = File.OpenText("C:\\words.txt");
Random rand = new Random();
int next = rand.Next(1,10000);
for (int x = 0; x < next; x++)
sentence += r.ReadLine() + " ";
For some reason, the strings this method returns look like this:
CAR CAR CAR CAR CAR TIGER TIGER ROOSTER ROOSTER ROOSTER
If I insert the statement MessageBox.Show(sentence) after each iteration of the second loop, however, the string returne is exactly what I would expect; something like:
CAR APPLE DOG ZEBRA LION BEAR TIGER EMU ROOSTER FOX
This may be an utterly simple oversight, but I have gone over and over the logic and cannot seem to figure out why I am getting unexpected return values like in the first example.
Any ideas would be greatly appreciated.
Thanks ahead of time,