I'm trying to create a file with 1000 line of random numbers separated by space. This is just to simulate the numbers of a lotto machine. I create a class that will handle the combination of the six number in an array of 6 int.
class cTicket
{
//Propiedades
private volatile int[] p_nums;
//Constructor
public cTicket()
{
}
//Metodos
public void setTicket(int[] o_nums)
{
p_nums = o_nums;
}
public int[] getTicket()
{
return p_nums;
}
}
like I said I need to create a combination of 1000 lines with an array of 6 number selected in a random way. So at some point of the code I got something like this:
private void button2_Click(object sender, EventArgs e)
{
for (int i = 0; i < 1000; i++) // Bucle de 1,000 combinaciones
{
objTicket.setTicket(objGenerador.generaNumero());
//MessageBox.Show(integerArrayString(objTicket.getTicket()));
write.WriteLine(i + integerArrayString(objTicket.getTicket()));
}
write.Close(); // Cierra operacion de escritura del archivo
}
But this part is not working at all. It repeat the same combination of 6 numbers over and over again. Only change like three times the whole process, another thing that I notice is that if I put the output in a message box it work perfect. But not when I try to write it into the file.
I hope someone can help with my problem.
Thanks.
Hi, thanks again, after reading the post below and get more documentation i get to the seed of the problem and it was the way that i generate the ramdom numbers as you guy says.
public int[] generaNumero() {
Random obj = new Random();
int v_idx;
for (int x = 0; x < 6; x++)
{
v_idx = x;
v_array[x] = obj.Next(1, 38);
while (v_idx >= 0)
{
if (v_array[x] == v_array[v_idx])
{
v_array[x] = obj.Next(1, 38);
v_idx = x;
}
v_idx--;
}
}
return v_array;
i just simple remove the line were i do the intance "Random obj = new Random();" from this method and its working perfect now.
thanks a lot.