Skip to content

Commit

Permalink
[Ref] mpt/random/device.hpp: Remove redundant state.
Browse files Browse the repository at this point in the history
git-svn-id: https://source.openmpt.org/svn/openmpt/trunk/OpenMPT@20757 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
manxorist committed May 11, 2024
1 parent b4732f4 commit 8a370c2
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/mpt/random/device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ class sane_random_device {
std::string token;
#if !defined(MPT_COMPILER_QUIRK_RANDOM_NO_RANDOM_DEVICE)
std::unique_ptr<std::random_device> prd;
bool rd_reliable{false};
#endif // !MPT_COMPILER_QUIRK_RANDOM_NO_RANDOM_DEVICE
std::unique_ptr<std::mt19937> rd_fallback;

Expand Down Expand Up @@ -164,13 +163,12 @@ class sane_random_device {
#if !defined(MPT_COMPILER_QUIRK_RANDOM_NO_RANDOM_DEVICE)
try {
prd = std::make_unique<std::random_device>();
rd_reliable = ((*prd).entropy() > 0.0);
if (!((*prd).entropy() > 0.0)) {
init_fallback();
}
} catch (mpt::out_of_memory e) {
mpt::rethrow_out_of_memory(e);
} catch (const std::exception &) {
rd_reliable = false;
}
if (!rd_reliable) {
init_fallback();
}
#else // MPT_COMPILER_QUIRK_RANDOM_NO_RANDOM_DEVICE
Expand All @@ -182,13 +180,12 @@ class sane_random_device {
#if !defined(MPT_COMPILER_QUIRK_RANDOM_NO_RANDOM_DEVICE)
try {
prd = std::make_unique<std::random_device>(token);
rd_reliable = ((*prd).entropy() > 0.0);
if (!((*prd).entropy() > 0.0)) {
init_fallback();
}
} catch (mpt::out_of_memory e) {
mpt::rethrow_out_of_memory(e);
} catch (const std::exception &) {
rd_reliable = false;
}
if (!rd_reliable) {
init_fallback();
}
#else // MPT_COMPILER_QUIRK_RANDOM_NO_RANDOM_DEVICE
Expand Down Expand Up @@ -239,13 +236,10 @@ class sane_random_device {
}
}
} catch (const std::exception &) {
rd_reliable = false;
init_fallback();
}
} else {
rd_reliable = false;
}
if (!rd_reliable) {
if (rd_fallback) {
// std::random_device is unreliable
// XOR the generated random number with more entropy from the time-seeded
// PRNG.
Expand Down

0 comments on commit 8a370c2

Please sign in to comment.