Skip to content

Commit

Permalink
Merged revision(s) 21549 from trunk/OpenMPT:
Browse files Browse the repository at this point in the history
[Fix] mpt/random/engine.hpp: The size calculation for the required seed_seq was wrong, resulting in way too much entropy to get requested.
........


git-svn-id: https://source.openmpt.org/svn/openmpt/branches/OpenMPT-1.31@21550 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
manxorist committed Aug 31, 2024
1 parent ea66cbc commit 44b604e
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/mpt/random/engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "mpt/base/macros.hpp"
#include "mpt/base/namespace.hpp"
#include "mpt/base/numeric.hpp"
#include "mpt/random/seed.hpp"

#include <memory>
Expand Down Expand Up @@ -47,7 +48,7 @@ struct engine_traits<std::mt19937> {
}
template <typename Trd>
static inline rng_type make(Trd & rd) {
std::unique_ptr<mpt::seed_seq_values<seed_bits / sizeof(unsigned int)>> values = std::make_unique<mpt::seed_seq_values<seed_bits / sizeof(unsigned int)>>(rd);
std::unique_ptr<mpt::seed_seq_values<mpt::align_up<std::size_t>(seed_bits, sizeof(unsigned int) * 8) / (sizeof(unsigned int) * 8)>> values = std::make_unique<mpt::seed_seq_values<mpt::align_up<std::size_t>(seed_bits, sizeof(unsigned int) * 8) / (sizeof(unsigned int) * 8)>>(rd);
std::seed_seq seed(values->begin(), values->end());
return rng_type(seed);
}
Expand All @@ -65,7 +66,7 @@ struct engine_traits<std::mt19937_64> {
}
template <typename Trd>
static inline rng_type make(Trd & rd) {
std::unique_ptr<mpt::seed_seq_values<seed_bits / sizeof(unsigned int)>> values = std::make_unique<mpt::seed_seq_values<seed_bits / sizeof(unsigned int)>>(rd);
std::unique_ptr<mpt::seed_seq_values<mpt::align_up<std::size_t>(seed_bits, sizeof(unsigned int) * 8) / (sizeof(unsigned int) * 8)>> values = std::make_unique<mpt::seed_seq_values<mpt::align_up<std::size_t>(seed_bits, sizeof(unsigned int) * 8) / (sizeof(unsigned int) * 8)>>(rd);
std::seed_seq seed(values->begin(), values->end());
return rng_type(seed);
}
Expand All @@ -83,7 +84,7 @@ struct engine_traits<std::ranlux24_base> {
}
template <typename Trd>
static inline rng_type make(Trd & rd) {
mpt::seed_seq_values<seed_bits / sizeof(unsigned int)> values(rd);
mpt::seed_seq_values<mpt::align_up<std::size_t>(seed_bits, sizeof(unsigned int) * 8) / (sizeof(unsigned int) * 8)> values(rd);
std::seed_seq seed(values.begin(), values.end());
return rng_type(seed);
}
Expand All @@ -101,7 +102,7 @@ struct engine_traits<std::ranlux48_base> {
}
template <typename Trd>
static inline rng_type make(Trd & rd) {
mpt::seed_seq_values<seed_bits / sizeof(unsigned int)> values(rd);
mpt::seed_seq_values<mpt::align_up<std::size_t>(seed_bits, sizeof(unsigned int) * 8) / (sizeof(unsigned int) * 8)> values(rd);
std::seed_seq seed(values.begin(), values.end());
return rng_type(seed);
}
Expand All @@ -119,7 +120,7 @@ struct engine_traits<std::ranlux24> {
}
template <typename Trd>
static inline rng_type make(Trd & rd) {
mpt::seed_seq_values<seed_bits / sizeof(unsigned int)> values(rd);
mpt::seed_seq_values<mpt::align_up<std::size_t>(seed_bits, sizeof(unsigned int) * 8) / (sizeof(unsigned int) * 8)> values(rd);
std::seed_seq seed(values.begin(), values.end());
return rng_type(seed);
}
Expand All @@ -137,7 +138,7 @@ struct engine_traits<std::ranlux48> {
}
template <typename Trd>
static inline rng_type make(Trd & rd) {
mpt::seed_seq_values<seed_bits / sizeof(unsigned int)> values(rd);
mpt::seed_seq_values<mpt::align_up<std::size_t>(seed_bits, sizeof(unsigned int) * 8) / (sizeof(unsigned int) * 8)> values(rd);
std::seed_seq seed(values.begin(), values.end());
return rng_type(seed);
}
Expand Down

0 comments on commit 44b604e

Please sign in to comment.