aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/CMakeLists.txt2
-rw-r--r--src/common/random.cpp19
-rw-r--r--src/common/random.h13
-rw-r--r--src/common/tiny_mt.h8
-rw-r--r--src/common/uuid.cpp11
5 files changed, 40 insertions, 13 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 1ee4794272..98c1688441 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -134,6 +134,8 @@ add_library(
typed_address.h
uint128.h
unique_function.h
+ random.cpp
+ random.h
uuid.cpp
uuid.h
vector_math.h
diff --git a/src/common/random.cpp b/src/common/random.cpp
new file mode 100644
index 0000000000..d6865ee807
--- /dev/null
+++ b/src/common/random.cpp
@@ -0,0 +1,19 @@
+// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#include <random>
+#include "common/random.h"
+
+static std::random_device g_random_device;
+
+namespace Common::Random {
+ [[nodiscard]] u32 Random32(u32 seed) noexcept {
+ return g_random_device();
+ }
+ [[nodiscard]] u64 Random64(u64 seed) noexcept {
+ return g_random_device();
+ }
+ [[nodiscard]] std::mt19937 GetMT19937() noexcept {
+ return std::mt19937(g_random_device());
+ }
+}
diff --git a/src/common/random.h b/src/common/random.h
new file mode 100644
index 0000000000..83210f6dc2
--- /dev/null
+++ b/src/common/random.h
@@ -0,0 +1,13 @@
+// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
+// SPDX-License-Identifier: GPL-3.0-or-later
+
+#pragma once
+
+#include <random>
+#include "common/common_types.h"
+
+namespace Common::Random {
+ [[nodiscard]] u32 Random32(u32 seed) noexcept;
+ [[nodiscard]] u64 Random64(u64 seed) noexcept;
+ [[nodiscard]] std::mt19937 GetMT19937() noexcept;
+}
diff --git a/src/common/tiny_mt.h b/src/common/tiny_mt.h
index c9f9ed4a5d..4b556a33eb 100644
--- a/src/common/tiny_mt.h
+++ b/src/common/tiny_mt.h
@@ -1,4 +1,4 @@
-// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
+// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: Copyright 2021 yuzu Emulator Project
@@ -218,12 +218,6 @@ public:
return t0;
}
- u64 GenerateRandomU64() {
- const u32 lo = this->GenerateRandomU32();
- const u32 hi = this->GenerateRandomU32();
- return (u64{hi} << 32) | u64{lo};
- }
-
float GenerateRandomF32() {
// Floats have 24 bits of mantissa.
constexpr u32 MantissaBits = 24;
diff --git a/src/common/uuid.cpp b/src/common/uuid.cpp
index 8f0dba452c..d4a5733c26 100644
--- a/src/common/uuid.cpp
+++ b/src/common/uuid.cpp
@@ -1,3 +1,6 @@
+// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
+// SPDX-License-Identifier: GPL-3.0-or-later
+
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
@@ -10,6 +13,7 @@
#include "common/assert.h"
#include "common/tiny_mt.h"
#include "common/uuid.h"
+#include "common/random.h"
namespace Common {
@@ -175,21 +179,16 @@ u128 UUID::AsU128() const {
}
UUID UUID::MakeRandom() {
- std::random_device device;
-
- return MakeRandomWithSeed(device());
+ return MakeRandomWithSeed(Common::Random::Random32(0));
}
UUID UUID::MakeRandomWithSeed(u32 seed) {
// Create and initialize our RNG.
TinyMT rng;
rng.Initialize(seed);
-
UUID uuid;
-
// Populate the UUID with random bytes.
rng.GenerateRandomBytes(uuid.uuid.data(), sizeof(UUID));
-
return uuid;
}