Skip to content

Commit

Permalink
implement utility functions: issue ProAlgos#99
Browse files Browse the repository at this point in the history
  • Loading branch information
mrKappen committed Oct 2, 2018
1 parent 3b3187f commit 3824e79
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions C++/include/utils/data_validation.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Various utility functions used for data validation
*/
#include <string>
#include <random>
#include <ctime>
#define UP_A 65
#define UP_Z 91

#define LOW_A 97
#define LOW_Z 122

std::string to_upper_case(std::string &s){
std::string upper;
for(int i = 0; i<s.length();i++){
if( s.at(i) >= LOW_A && s.at(i) <= LOW_Z){
upper+=(s.at(i) - 32);
}else{
upper += s.at(i);
}
}
return upper;
}

std::string to_lower_case(std::string &s){
std::string lower;
for(int i = 0; i<s.length();i++){
if( s.at(i) >= UP_A && s.at(i) <= UP_Z){
lower+=(s.at(i) + 32);
}else{
lower += s.at(i);
}
}
return lower;
}

double get_random_double(double min, double max){
std::mt19937 generator;
generator.seed(std::time(0));
std::uniform_real_distribution<double> random_double(min,max);
double random_double_value = random_double(generator);
return random_double_value;
}

int get_random_int(int min, int max){
std::mt19937 generator;
generator.seed(std::time(0));
std::uniform_int_distribution<uint32_t> random_int(min,max);
int random_integer = random_int(generator);
return random_integer;
}

0 comments on commit 3824e79

Please sign in to comment.