diff options
Diffstat (limited to '')
| -rw-r--r-- | src/core/hle/kernel/memory/system_control.cpp | 21 | ||||
| -rw-r--r-- | src/core/hle/kernel/memory/system_control.h | 5 |
2 files changed, 11 insertions, 15 deletions
diff --git a/src/core/hle/kernel/memory/system_control.cpp b/src/core/hle/kernel/memory/system_control.cpp index 2f98e9c4c..11d204bc2 100644 --- a/src/core/hle/kernel/memory/system_control.cpp +++ b/src/core/hle/kernel/memory/system_control.cpp | |||
| @@ -7,22 +7,15 @@ | |||
| 7 | #include "core/hle/kernel/memory/system_control.h" | 7 | #include "core/hle/kernel/memory/system_control.h" |
| 8 | 8 | ||
| 9 | namespace Kernel::Memory::SystemControl { | 9 | namespace Kernel::Memory::SystemControl { |
| 10 | 10 | namespace { | |
| 11 | u64 GenerateRandomU64ForInit() { | ||
| 12 | static std::random_device device; | ||
| 13 | static std::mt19937 gen(device()); | ||
| 14 | static std::uniform_int_distribution<u64> distribution(1, std::numeric_limits<u64>::max()); | ||
| 15 | return distribution(gen); | ||
| 16 | } | ||
| 17 | |||
| 18 | template <typename F> | 11 | template <typename F> |
| 19 | u64 GenerateUniformRange(u64 min, u64 max, F f) { | 12 | u64 GenerateUniformRange(u64 min, u64 max, F f) { |
| 20 | /* Handle the case where the difference is too large to represent. */ | 13 | // Handle the case where the difference is too large to represent. |
| 21 | if (max == std::numeric_limits<u64>::max() && min == std::numeric_limits<u64>::min()) { | 14 | if (max == std::numeric_limits<u64>::max() && min == std::numeric_limits<u64>::min()) { |
| 22 | return f(); | 15 | return f(); |
| 23 | } | 16 | } |
| 24 | 17 | ||
| 25 | /* Iterate until we get a value in range. */ | 18 | // Iterate until we get a value in range. |
| 26 | const u64 range_size = ((max + 1) - min); | 19 | const u64 range_size = ((max + 1) - min); |
| 27 | const u64 effective_max = (std::numeric_limits<u64>::max() / range_size) * range_size; | 20 | const u64 effective_max = (std::numeric_limits<u64>::max() / range_size) * range_size; |
| 28 | while (true) { | 21 | while (true) { |
| @@ -32,6 +25,14 @@ u64 GenerateUniformRange(u64 min, u64 max, F f) { | |||
| 32 | } | 25 | } |
| 33 | } | 26 | } |
| 34 | 27 | ||
| 28 | u64 GenerateRandomU64ForInit() { | ||
| 29 | static std::random_device device; | ||
| 30 | static std::mt19937 gen(device()); | ||
| 31 | static std::uniform_int_distribution<u64> distribution(1, std::numeric_limits<u64>::max()); | ||
| 32 | return distribution(gen); | ||
| 33 | } | ||
| 34 | } // Anonymous namespace | ||
| 35 | |||
| 35 | u64 GenerateRandomRange(u64 min, u64 max) { | 36 | u64 GenerateRandomRange(u64 min, u64 max) { |
| 36 | return GenerateUniformRange(min, max, GenerateRandomU64ForInit); | 37 | return GenerateUniformRange(min, max, GenerateRandomU64ForInit); |
| 37 | } | 38 | } |
diff --git a/src/core/hle/kernel/memory/system_control.h b/src/core/hle/kernel/memory/system_control.h index 3fa93111d..19cab8cbc 100644 --- a/src/core/hle/kernel/memory/system_control.h +++ b/src/core/hle/kernel/memory/system_control.h | |||
| @@ -8,11 +8,6 @@ | |||
| 8 | 8 | ||
| 9 | namespace Kernel::Memory::SystemControl { | 9 | namespace Kernel::Memory::SystemControl { |
| 10 | 10 | ||
| 11 | u64 GenerateRandomU64ForInit(); | ||
| 12 | |||
| 13 | template <typename F> | ||
| 14 | u64 GenerateUniformRange(u64 min, u64 max, F f); | ||
| 15 | |||
| 16 | u64 GenerateRandomRange(u64 min, u64 max); | 11 | u64 GenerateRandomRange(u64 min, u64 max); |
| 17 | 12 | ||
| 18 | } // namespace Kernel::Memory::SystemControl | 13 | } // namespace Kernel::Memory::SystemControl |