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{}()};