1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
#ifndef RAND_NUM_H
#define RAND_NUM_H
#include <iostream>
#include <random>
#include <chrono>
#include <time.h>
#include <stdio.h>
int printRandomInt(int min, int max) {
unsigned long seed = (unsigned long) std::chrono::steady_clock::now().time_since_epoch().count();
std::default_random_engine e1(seed);
std::uniform_int_distribution<int> distrA(min, max); //this is an inclusive range [min, max]
return distrA(e1); //This is fine to use for he project
}
double printRandomDouble(double min, double max) {
unsigned long seed = (unsigned long) std::chrono::steady_clock::now().time_since_epoch().count();
std::default_random_engine e2(seed);
std::uniform_real_distribution<double> distrB(min, max); //this is an inclusive-not inclusive range [min, max)
return distrB(e2); //This is fine to use for he project
}
float printRandomFloat(float min, float max) {
unsigned long seed = (unsigned long) std::chrono::steady_clock::now().time_since_epoch().count();
std::default_random_engine e3(seed);
std::uniform_real_distribution<float> distrC(min, max); //this is an inclusive-not inclusive range [min, max)
return distrC(e3); //This is fine to use for he project
}
double NormalDistributedVals(double x2, double mu_1, double mu_2, double sigma_1, double sigma_2, double rho) {
unsigned long seed = (unsigned long) std::chrono::steady_clock::now().time_since_epoch().count();
std::default_random_engine e4(seed);
double output;
std::normal_distribution<double> distrN(mu_1 + (sigma_1 / sigma_2)*rho*(x2 - mu_2), sqrt(1 - pow(rho, 2)* pow(sigma_1, 2)));
output = distrN(e4);
return output;
}
#endif /*RAND_NUM_H*/
| |