Explictly use 64-bit random engine

Avoids downcasting issues for the seed on platforms where the random
engine is actually 32-bit.

Change-Id: Ia9e4cffb688e7c82f3f088b71f99002b76ad1df3
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/65640
Auto-Submit: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Ryan Harrison 2021-10-04 14:40:26 +00:00 committed by Tint LUCI CQ
parent 2271b9541c
commit 7f3b68edd5
2 changed files with 5 additions and 5 deletions

View File

@ -32,7 +32,7 @@ namespace {
/// @param upper - Upper bound of integer generated
/// @returns i, where lower <= i < upper
template <typename I>
I RandomUInt(std::mt19937* engine, I lower, I upper) {
I RandomUInt(std::mt19937_64* engine, I lower, I upper) {
assert(lower < upper && "|lower| must be stictly less than |upper|");
return std::uniform_int_distribution<I>(lower, upper - 1)(*engine);
@ -80,18 +80,18 @@ uint64_t RandomGenerator::GetUInt64(uint64_t bound) {
}
uint8_t RandomGenerator::GetByte() {
return std::independent_bits_engine<std::mt19937, 8, uint8_t>(engine_)();
return std::independent_bits_engine<std::mt19937_64, 8, uint8_t>(engine_)();
}
uint32_t RandomGenerator::Get4Bytes() {
return std::independent_bits_engine<std::mt19937, 32, uint32_t>(engine_)();
return std::independent_bits_engine<std::mt19937_64, 32, uint32_t>(engine_)();
}
void RandomGenerator::GetNBytes(uint8_t* dest, size_t n) {
assert(dest && "|dest| must not be nullptr");
std::generate(
dest, dest + n,
std::independent_bits_engine<std::mt19937, 8, uint8_t>(engine_));
std::independent_bits_engine<std::mt19937_64, 8, uint8_t>(engine_));
}
bool RandomGenerator::GetBool() {

View File

@ -98,7 +98,7 @@ class RandomGenerator {
}
private:
std::mt19937 engine_;
std::mt19937_64 engine_;
}; // class RandomGenerator