Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
psemiletov committed Apr 9, 2023
1 parent 1f08d9e commit 7f44ced
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 33 deletions.
73 changes: 43 additions & 30 deletions macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,6 @@
#include <chrono>


#ifdef USE_PROM

#include "prometheus/client_metric.h"
#include "prometheus/counter.h"
#include "prometheus/exposer.h"
#include "prometheus/family.h"
#include "prometheus/info.h"
#include "prometheus/registry.h"

#endif


#include "utl.h"
#include "macro.h"
Expand All @@ -27,6 +16,15 @@ using namespace std;
char arr_nums [] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};


std::mt19937 rnd_mt19937;


void rnd_init()
{
rnd_mt19937.seed (std::chrono::system_clock::now().time_since_epoch().count());
}

/*
std::mt19937 &mt()
{
// initialize once per thread
Expand All @@ -38,12 +36,12 @@ std::mt19937 &mt()
return smt;
}

*/

int get_rnd (int ta, int tb)
{
std::uniform_int_distribution <> distrib (ta, tb);
return distrib (mt());
return distrib (rnd_mt19937);
}


Expand All @@ -56,7 +54,7 @@ string gen_string (size_t len)

for (size_t i = 0; i < len; i++)
{
int g = distrib (mt());
int g = distrib (rnd_mt19937);
char d = static_cast<char> (g + 'a');
result += d;
}
Expand All @@ -72,11 +70,11 @@ string gen_string (size_t min, size_t max)

std::uniform_int_distribution<> distrib (0, 25);
std::uniform_int_distribution<> dminmax (min, max);
size_t len = dminmax (mt());
size_t len = dminmax (rnd_mt19937);

for (size_t i = 0; i < len; i++)
{
int g = distrib (mt());
int g = distrib (rnd_mt19937);
char d = static_cast<char> (g + 'a');
result += d;
}
Expand Down Expand Up @@ -113,7 +111,7 @@ string gen_number (size_t len)

for (size_t i = 0; i < len; i++)
{
result += arr_nums[distrib (mt())];
result += arr_nums[distrib (rnd_mt19937)];
}

return result;
Expand All @@ -124,14 +122,14 @@ string gen_number (size_t min, size_t max)
{
std::uniform_int_distribution<> distrib (0, 9);
std::uniform_int_distribution<> dminmax (min, max);
size_t len = dminmax (mt());
size_t len = dminmax (rnd_mt19937);

string result;
result.reserve (len);

for (size_t i = 0; i < len; i++)
{
result += arr_nums[distrib (mt())];
result += arr_nums[distrib (rnd_mt19937)];
}

return result;
Expand All @@ -147,7 +145,7 @@ string gen_hex_number (size_t len)

for (size_t i = 0; i < len; i++)
{
result += arr_nums[distrib (mt())];
result += arr_nums[distrib (rnd_mt19937)];
}

return result;
Expand All @@ -158,14 +156,14 @@ string gen_hex_number (size_t min, size_t max)
{
std::uniform_int_distribution<> distrib (0, 15);
std::uniform_int_distribution<> dminmax (min, max);
size_t len = dminmax (mt());
size_t len = dminmax (rnd_mt19937);

string result;
result.reserve (len);

for (size_t i = 0; i < len; i++)
{
result += arr_nums[distrib (mt())];
result += arr_nums[distrib (rnd_mt19937)];
}

return result;
Expand Down Expand Up @@ -245,16 +243,16 @@ string CMacroIPRandom::process()
string result;
result.reserve (16);

result += to_string (distrib (mt()));
result += to_string (distrib (rnd_mt19937));
result += ".";

result += to_string (distrib (mt()));
result += to_string (distrib (rnd_mt19937));
result += ".";

result += to_string (distrib (mt()));
result += to_string (distrib (rnd_mt19937));
result += ".";

result += to_string (distrib (mt()));
result += to_string (distrib (rnd_mt19937));

return result;
}
Expand Down Expand Up @@ -439,7 +437,7 @@ void CMacroPathRandom::parse (const string &s)

string CMacroPathRandom::process()
{
return gen_rnd_path (len_min, len_max, length);
return gen_rnd_path (len_min, len_max, length);
}


Expand Down Expand Up @@ -490,19 +488,34 @@ vector <string> split_string_to_vector_a (const string &s, char delimeter, char

void CMacroSeq::parse (const string &s)
{
// cout << "void CMacroSeq::parse: " << s << endl;

len_min = 0;
len_max = 0;
length = 0;
text = "";

vt = split_string_to_vector_a (s, ':', '/');
// vt = split_string_to_vector_a (s, ':', '/');
vt = split_string_to_vector (s, ":");


}


string CMacroSeq::process()
{
// cout << "CMacroSeq::process() 1" << endl;

//cout << "vt.size(): " << vt.size() << endl;

size_t i = get_rnd (1, vt.size() - 1);

// cout << "CMacroSeq::process() 2:" << i << endl;


// cout << "CMacroSeq::process() 3" << endl;


return vt[i];
}

Expand Down Expand Up @@ -607,7 +620,7 @@ void CMacroMeta::parse (const string &s)
//create cached macro
string name = get_macro_name (macrotext);

cout << "name is: " << name << endl;
// cout << "name is: " << name << endl;

if (name.empty())
continue;
Expand All @@ -618,7 +631,7 @@ void CMacroMeta::parse (const string &s)

//copy metamacro instead of real one
string newname = "@" + to_string(i);
cout << "new name is: " << newname << endl;
// cout << "new name is: " << newname << endl;

meta += newname;

Expand Down
4 changes: 4 additions & 0 deletions macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <map>




class CMacro
{
public:
Expand Down Expand Up @@ -184,4 +186,6 @@ class CMacroMeta: public CMacro
};


void rnd_init();

#endif
1 change: 1 addition & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ int main (int argc, char *argv[])

std::string tdir = get_tmp_dir();

rnd_init();

std::string temp_logfile;
std::string temp_logfile0;
Expand Down
8 changes: 5 additions & 3 deletions vars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@

using namespace std;

extern std::mt19937 rnd_mt19937;

/*
std::mt19937 &vmt()
{
// initialize once per thread
Expand All @@ -28,7 +30,7 @@ std::mt19937 &vmt()
return smt;
}

*/


int get_value_nature (const string &s)
Expand Down Expand Up @@ -136,7 +138,7 @@ CVar::~CVar()
int CVar::get_rnd (int ta, int tb)
{
std::uniform_int_distribution <> distrib (ta, tb);
return distrib (vmt());
return distrib (rnd_mt19937);
}


Expand All @@ -148,7 +150,7 @@ string CVar::gen_msecs()
std::stringstream sstream;
sstream.setf (std::ios::fixed);
sstream.precision (precision);
sstream << distrib (vmt());
sstream << distrib (rnd_mt19937);

return sstream.str();
}
Expand Down

0 comments on commit 7f44ced

Please sign in to comment.