Commit 616c4b9d authored by Dianna Hu's avatar Dianna Hu Committed by Commit Bot

Update integer types for Http2Random.

This CL updates Http2Random to use unsigned integers consistently, in
hopes of being platform-agnostic (see, e.g.,
https://crrev.com/c/1310613).

This CL lands server changes 221087569 by bnc and 221279592 by diannahu.

Change-Id: Ifb1ea404887ab46569572a27b0c61c7e1bf1a26f
Reviewed-on: https://chromium-review.googlesource.com/c/1334009Reviewed-by: default avatarBence Béky <bnc@chromium.org>
Commit-Queue: Dianna Hu <diannahu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#607736}
parent 2471aebe
...@@ -38,19 +38,19 @@ class Http2Random { ...@@ -38,19 +38,19 @@ class Http2Random {
uint64_t Rand64(); uint64_t Rand64();
// Return a uniformly distrubted random number in [0, n). // Return a uniformly distrubted random number in [0, n).
int32_t Uniform(int32_t n) { return Rand64() % n; } uint32_t Uniform(uint32_t n) { return Rand64() % n; }
// Return a uniformly distrubted random number in [lo, hi). // Return a uniformly distrubted random number in [lo, hi).
int64_t UniformInRange(int64_t lo, int64_t hi) { uint64_t UniformInRange(uint64_t lo, uint64_t hi) {
return lo + Rand64() % (hi - lo); return lo + Rand64() % (hi - lo);
} }
// Return an integer of logarithmically random scale. // Return an integer of logarithmically random scale.
int32_t Skewed(int32_t max_log) { uint32_t Skewed(uint32_t max_log) {
const int32_t base = Rand32() % (max_log + 1); const uint32_t base = Rand32() % (max_log + 1);
const uint32_t mask = ((base < 32) ? (1u << base) : 0u) - 1u; const uint32_t mask = ((base < 32) ? (1u << base) : 0u) - 1u;
return Rand32() & mask; return Rand32() & mask;
} }
// Return a random number in [0, max] range that skews low. // Return a random number in [0, max] range that skews low.
size_t RandomSizeSkewedLow(size_t max) { uint64_t RandomSizeSkewedLow(uint64_t max) {
return std::round(max * std::pow(RandDouble(), 2)); return std::round(max * std::pow(RandDouble(), 2));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment