aboutsummaryrefslogtreecommitdiff
path: root/src/common/random.cpp
diff options
context:
space:
mode:
authorlizzie <lizzie@eden-emu.dev>2026-03-31 23:45:06 +0200
committercrueter <crueter@eden-emu.dev>2026-03-31 23:45:06 +0200
commit21f9db1c272c5fd55aea2c9390535139a0782ba5 (patch)
tree30abe6613536223b783870a79e9869d91caba775 /src/common/random.cpp
parentb4a485e244a742ce7ae2960b25ae0ab67bb0f5f2 (diff)
[android] fix crash due to ctor/dtor ordering for std::random_device being uninitialized when used in other static ctor/dtors (#3806)
wow that's fucking horrible Signed-off-by: lizzie <lizzie@eden-emu.dev> Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/3806 Reviewed-by: MaranBr <maranbr@eden-emu.dev> Reviewed-by: CamilleLaVey <camillelavey99@gmail.com> Co-authored-by: lizzie <lizzie@eden-emu.dev> Co-committed-by: lizzie <lizzie@eden-emu.dev>
Diffstat (limited to 'src/common/random.cpp')
-rw-r--r--src/common/random.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/common/random.cpp b/src/common/random.cpp
index d6865ee807..d951881cd2 100644
--- a/src/common/random.cpp
+++ b/src/common/random.cpp
@@ -1,19 +1,22 @@
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
// SPDX-License-Identifier: GPL-3.0-or-later
+#include <optional>
#include <random>
#include "common/random.h"
-static std::random_device g_random_device;
-
namespace Common::Random {
+ [[nodiscard]] static std::random_device& GetGlobalRandomDevice() noexcept {
+ static std::random_device g_random_device{};
+ return g_random_device;
+ }
[[nodiscard]] u32 Random32(u32 seed) noexcept {
- return g_random_device();
+ return GetGlobalRandomDevice()();
}
[[nodiscard]] u64 Random64(u64 seed) noexcept {
- return g_random_device();
+ return GetGlobalRandomDevice()();
}
[[nodiscard]] std::mt19937 GetMT19937() noexcept {
- return std::mt19937(g_random_device());
+ return std::mt19937(GetGlobalRandomDevice()());
}
}