jeudi 17 septembre 2020

Passing arbitrary random number distributions to a function

I am writing a matrix initialization method that fills a matrix of type T with random numbers of type T from a random number distribution that the user can choose. The section of my implementation file would look something like

// file name: Matrix.h
#include <random>

typedef std::default_random_engine rnd_eng;

template<class T, int N, int M>
class Matrix{
  private:
    /* private members here */
  public:
    Matrix<T, N, M>();
    /* other constructors */
    ~/Matrix<T, N, M>();

    void init_all(T value); // initializes all elements of Matrix NxM to value
    void init_Random(rnd_eng, USER RANDOM NUMBER DISTRIBUTION HERE);
};

/*
  Ideally I would have something that looks like the following in a main.cpp file
    rnd_eng engine(1);
    std::uniform_real_distribution real_dist(1.0f, 1.0f);
    std::uniform_int_distribution int_dist(1, 9);

    Matrix<float, 32, 64> my_mat_a;
    Matrix<int, 128, 256> my_mat_b;

    my_mat_a.init_Random(engine, real_dist);
    my_mat_b.init_Random(engine, int_dist);
*/

I would like to know what would go in place of "USER RANDOM NUMBER DISTRIBUTION HERE". Do you guys have any suggestions? Apologies if this is a basic question.

** Edit: made my question a bit clearer hopefully




Aucun commentaire:

Enregistrer un commentaire