diff --git a/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc b/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc index 58c1ebad39e..279f480946f 100644 --- a/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +++ b/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc @@ -638,9 +638,8 @@ void XdsLb::PickerWrapper::RecordCallCompletion( 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. return PickFromLocality(key, args);