I have put together some code to generate multiple arrays of random numbers. The code generates a different array of random numbers every time, but when I try to write each new set of numbers to an individual text file each file has the same numbers written to them (those from the first array generated). Does anyone know how I can edit the code so that each file has a different array written to it? I'll add the code that shows how the numbers are generated if it helps.
for (int repeat = 0; repeat < 100; repeat++)
{
Random random = new Random();
int[] randomNumbers = new int[50];
int[] array = new int[6];
//Generate array of random numbers
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"c:\CodeFolder\repeat.ToString() + ".txt"))
{
foreach (int number in array)
{
file.WriteLine(number);
}
}
}
Edit: Sorry about that. Part of the code used in the first post was incorrectly typed. Anyway, I have edited the code so that now it works like this.
string fileName = repeat.ToString();
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"c:\CodeFolder\" + fileName + ".txt"))
This time around the first file has a unique array of numbers written to it, but every other file contains the same array. Not too sure what's going on with it.