common/util: move function random_int to util (#29388)

This commit is contained in:
Dean Lee
2023-08-15 00:37:16 +08:00
committed by GitHub
parent 29f2389cce
commit 22bc06fdaa
4 changed files with 15 additions and 19 deletions
+7
View File
@@ -213,6 +213,13 @@ std::string hexdump(const uint8_t* in, const size_t size) {
return ss.str();
}
int random_int(int min, int max) {
std::random_device dev;
std::mt19937 rng(dev());
std::uniform_int_distribution<std::mt19937::result_type> dist(min, max);
return dist(rng);
}
std::string random_string(std::string::size_type length) {
const std::string chrs = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
std::mt19937 rg{std::random_device{}()};
+4 -1
View File
@@ -75,9 +75,12 @@ int getenv(const char* key, int default_val);
float getenv(const char* key, float default_val);
std::string hexdump(const uint8_t* in, const size_t size);
std::string random_string(std::string::size_type length);
std::string dir_name(std::string const& path);
// ***** random helpers *****
int random_int(int min, int max);
std::string random_string(std::string::size_type length);
// **** file fhelpers *****
std::string read_file(const std::string& fn);
std::map<std::string, std::string> read_files_in_dir(const std::string& path);