Fix key gen in locality picking

pull/19859/head
Juanli Shen 6 years ago
parent 6ba7d2c21d
commit 6522294325
  1. 5
      src/core/ext/filters/client_channel/lb_policy/xds/xds.cc

@ -559,9 +559,8 @@ class XdsLb : public LoadBalancingPolicy {
XdsLb::PickResult XdsLb::Picker::Pick(PickArgs args) {
// TODO(roth): Add support for drop handling.
// Generate a random number between 0 and the total weight
const uint32_t key =
(rand() * pickers_[pickers_.size() - 1].first) / RAND_MAX;
// Generate a random number in [0, total weight).
const uint32_t key = rand() % pickers_[pickers_.size() - 1].first;
// Forward pick to whichever locality maps to the range in which the
// random number falls in.
PickResult result = PickFromLocality(key, args);

Loading…
Cancel
Save