I'm trying to create a class that can generate a random variable. I want to be able to generate any random type based on the templated value at runtime. I figured I can do this by making this function works for ints, strings, and double data types by coding each one specifically.
template <typename T>
class Generator{
private:
int upper_bound;
int lower_bound;
int size;
vector<T> data;
vector<int> keys;
public:
Generator(int size, int lower_bound, int upper_bound){
this->size = size;
this->upper_bound = upper_bound;
this->lower_bound = lower_bound;
}
void generate_keys(){
//key generater
int rand_num;
int row = 0;
//uses srand and rand to get generator random keys and random data
srand(time(0));
cout << "Generating the keys now..." << endl;
cout << "upper bound - " << get_upper_bound() << endl;
for(int i=0;i < size;i++){
//rand_num = dist(rng);
rand_num = (rand()%upper_bound)+lower_bound;
cout << rand_num << " ";
keys.push_back(rand_num);
row++;
if(row == 3){
cout << endl;
row = 0;
}
}
cout << endl;
}
//templated so this function can work with strings, doubles, and ints
void generate_data(){
}