Как лучше всего случайно сгенерировать числа разных типов(int, double,float) используя шаблон?
Написал программу, которая должна генерировать числа в зависимости от выбора пользователя.Но столкнулся с проблемой - генерируются только числа типа int и double. Как сделать так, что бы ещё генерировались числа типа float?
#include <iostream>
#include <math.h>
#include <time.h>
#define SIZE 10
using namespace std;
template <typename T>
void printA(T* arr)
{
for (int i = 0; i < SIZE; i++)
{
cout << arr[i] << " ";
}
}
template <typename T>
void Generation(T* arr, T xmin,T xmax)
{
for (int i = 0; i < SIZE; i++)
{
arr[i] = 999 + static_cast <T> (rand()) /( static_cast <T> (RAND_MAX/(999 - 1)));
}
printA(arr);
}
void Choise_Type()
{
cout << "n1) int\n2) double\n3) float\n";
int type;
cin >> type;
switch(type)
{
case 1:
{
int arr_int = nullptr;
arr_int = new int[SIZE];
Generation(arr_int, 1, 100);
}
break;
case 2:
{
doublearr_doub = nullptr;
arr_doub = new double[SIZE];
Generation(arr_doub, 0.0, 100.0);
}
break;
case 3:
{
float *arr_fl = nullptr;
arr_fl = new float[SIZE];
Generation(arr_fl, 0.0f, 100.0f);
}
break;
}
}
int main()
{
Choise_Type();
}