mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-25 03:42:48 +01:00
Re-use the same random engine
as per https://github.com/rwengine/openrw/pull/682#discussion_r249476939
This commit is contained in:
parent
da8de34f7d
commit
74993e2a94
@ -92,17 +92,20 @@ protected:
|
||||
}
|
||||
|
||||
private:
|
||||
static std::default_random_engine& getRandomEngine() {
|
||||
static std::default_random_engine defaultRandomEngine = std::default_random_engine(std::random_device{}());
|
||||
return defaultRandomEngine;
|
||||
}
|
||||
static std::string gen_random(size_t len) {
|
||||
constexpr std::string_view alphanum =
|
||||
"0123456789"
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
"abcdefghijklmnopqrstuvwxyz";
|
||||
std::default_random_engine reng(std::random_device{}());
|
||||
std::uniform_int_distribution<size_t> dist(0u, alphanum.size());
|
||||
std::string res;
|
||||
res.reserve(len);
|
||||
std::generate_n(std::back_inserter(res), len, [&]() {
|
||||
return alphanum[dist(reng)];
|
||||
return alphanum[dist(getRandomEngine())];
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user