mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-11-27 01:04: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>
|
template<typename T>
|
||||||
requires std::is_integral_v<T>
|
requires std::is_integral_v<T>
|
||||||
void FillRandomBytes(std::span<T> in) {
|
void FillRandomBytes(std::span<T> in) {
|
||||||
std::independent_bits_engine<std::mt19937_64, std::numeric_limits<T>::digits, T> gen(detail::generator);
|
std::uniform_int_distribution<u64> dist(std::numeric_limits<T>::min(), std::numeric_limits<T>::max());
|
||||||
std::generate(in.begin(), in.end(), gen);
|
std::generate(in.begin(), in.end(), [&]() { return dist(detail::generator); });
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T>
|
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) {
|
void FillRandomBytes(T &object) {
|
||||||
FillRandomBytes(std::span(reinterpret_cast<typename IntegerFor<T>::Type *>(&object), IntegerFor<T>::Count));
|
FillRandomBytes(std::span(reinterpret_cast<typename IntegerFor<T>::Type *>(&object), IntegerFor<T>::Count));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user