mardi 11 mai 2021

2d_array random numbers (10Rows, 6 COLS) not repeated to file C#

I need to streamwrite into a file.txt a 10 random numbers combinations (NOT REPEATED) like lottery program. I got everything except Non-repeated random numbers. it has to be seen (file.txt) like a 2D array with 10 combinations thx.

class Matriz
{
    private int[,] array;
    private int nfilas, ncols;     

    public void Ingresar()
    {
        Random aleatori = new Random();
        nfilas = 10;
        ncols = 6;
        Console.WriteLine("\n");
        array = new int[nfilas, ncols];
        for (int filas = 0; filas < nfilas; filas++)
        {
            for (int columnas = 0; columnas < ncols; columnas++)
                array[filas, columnas] = aleatori.Next(0, 50);
        }
    }

    public void Imprimir()
    {
        StreamWriter fitxer = new StreamWriter(@"C:\andres\lotto649.txt");
        int contador = 0;
        for (int f = 0; f < nfilas; f++)
        {
            for (int c = 0; c < ncols; c++)                    
                fitxer.Write(array[f, c] + " ");

            fitxer.WriteLine();
            contador++;
        }
        fitxer.WriteLine($"\n\n\tHay {contador} combinaciones de la Loteria 6/49");
        fitxer.Close();
    }

    static void Main(string[] args)
    {            
        Matriz array_menu = new Matriz();
        array_menu.Ingresar();
        array_menu.Imprimir();           
       
    }
}



Aucun commentaire:

Enregistrer un commentaire