mirror of
https://github.com/Detanup01/gbe_fork.git
synced 2024-11-27 05:04:01 +08:00
helper function to generate rand num
This commit is contained in:
parent
663f1a9350
commit
e57daf02d0
@ -3,6 +3,7 @@
|
|||||||
#include <cwchar>
|
#include <cwchar>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
#include <random>
|
||||||
|
|
||||||
namespace common_helpers {
|
namespace common_helpers {
|
||||||
|
|
||||||
@ -396,3 +397,13 @@ bool common_helpers::dir_exist(const std::wstring &dirpath)
|
|||||||
if (dirpath.empty()) return false;
|
if (dirpath.empty()) return false;
|
||||||
return dir_exist(std::filesystem::path(dirpath));
|
return dir_exist(std::filesystem::path(dirpath));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t common_helpers::rand_number(size_t max)
|
||||||
|
{
|
||||||
|
// https://en.cppreference.com/w/cpp/numeric/random/uniform_int_distribution
|
||||||
|
std::random_device rd{}; // a seed source for the random number engine
|
||||||
|
std::mt19937 gen(rd()); // mersenne_twister_engine seeded with rd()
|
||||||
|
std::uniform_int_distribution<size_t> distrib(0, max);
|
||||||
|
|
||||||
|
return distrib(gen);
|
||||||
|
}
|
||||||
|
@ -98,4 +98,7 @@ bool dir_exist(const std::filesystem::path &dirpath);
|
|||||||
bool dir_exist(const std::string &dirpath);
|
bool dir_exist(const std::string &dirpath);
|
||||||
bool dir_exist(const std::wstring &dirpath);
|
bool dir_exist(const std::wstring &dirpath);
|
||||||
|
|
||||||
|
// between 0 and max, 0 and max are included
|
||||||
|
size_t rand_number(size_t max);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user