Common/Random: Add convenience template for simple arithmetic values

In cases where we just want a random value for a primitive arithmetic
type, we can wrap this in a template to allow convenient direct
assignment instead of keeping declaration and initialization separate
(making it more difficult to use values uninitialized). This also allows
the use of Common::Random with functions such as std::generate, making
it more flexible in how random values can be generated.
This commit is contained in:
Lioncash committed 2018-06-14 10:31:13 -04:00
1 parent e69c6cdaab
commit 189d277cfc
4 files changed
+15 -6

No files matched your search

+2 -3
View File
@@ -73,9 +73,8 @@ void DolphinAnalytics::ReloadConfig()
void DolphinAnalytics::GenerateNewIdentity()
{
u64 id_high, id_low;
Common::Random::Generate(&id_high, sizeof(id_high));
Common::Random::Generate(&id_low, sizeof(id_low));
const u64 id_high = Common::Random::GenerateValue<u64>();
const u64 id_low = Common::Random::GenerateValue<u64>();
m_unique_id = StringFromFormat("%016" PRIx64 "%016" PRIx64, id_high, id_low);
// Save the new id in the configuration.