vendredi 19 octobre 2018

two dimensional array with random numbers doesn't change

I'm creating an 2-dim Array with random numbers from [0,9] and it works, but after i execute it the second time the matrix doesn't change. Why ?

Everytime i execute my code i want a new random matrix, not the same from the old runtime. Where's the problem and how can i fix it?

#include <QCoreApplication>
#include <iostream>
#include <random>

constexpr int dim_rows = 3;
constexpr int dim_cols = 5;

template <size_t dim_rows, size_t dim_cols>
void print_2d_array(int (&outputArray)[dim_rows][dim_cols]){
    std::cout << __func__ << std::endl;
    for (size_t i = 0; i < dim_rows; i++){
        std::cout << i << ": ";
        for(size_t j = 0; j < dim_cols; j++) {
            std::cout << outputArray[i][j] << " ";
        }std::cout << std::endl;
    }
}

int main(int argc, char *argv[])
{
    std::default_random_engine generator;
    std::uniform_int_distribution <int> distribution(0,9);

    int twoDimA[dim_rows][dim_cols] = ;

    for(int i = 1; i < dim_rows; i++) {
        for(int j = 1; j < dim_cols; j++) {
            twoDimA[i][j] = distribution(generator);
        }
    }

    print_2d_array(twoDimA);
}




Aucun commentaire:

Enregistrer un commentaire