mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-11-26 21:54:16 +01:00
Fix FillRandomBytes
There were two issues here: - If a skyline span was passed as a param then the 'T &object' version would be called, filling the span itself with random values rather than its contents - Random numbers were repeated every call since independent_bits_engine copied generator state and thus it was never actually updated
This commit is contained in:
parent
622ff2a8f1
commit
15e9fa1c80
@ -237,12 +237,12 @@ namespace skyline::util {
|
||||
template<typename T>
|
||||
requires std::is_integral_v<T>
|
||||
void FillRandomBytes(std::span<T> in) {
|
||||
std::independent_bits_engine<std::mt19937_64, std::numeric_limits<T>::digits, T> gen(detail::generator);
|
||||
std::generate(in.begin(), in.end(), gen);
|
||||
std::uniform_int_distribution<u64> dist(std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
|
||||
std::generate(in.begin(), in.end(), [&]() { return dist(detail::generator); });
|
||||
}
|
||||
|
||||
template<class T>
|
||||
requires (!std::is_integral_v<T> && std::is_trivially_copyable_v<T>)
|
||||
requires (std::is_trivially_copyable_v<T> && !requires (T v) { v.data(); })
|
||||
void FillRandomBytes(T &object) {
|
||||
FillRandomBytes(std::span(reinterpret_cast<typename IntegerFor<T>::Type *>(&object), IntegerFor<T>::Count));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user