Reedy has uploaded a new change for review. https://gerrit.wikimedia.org/r/51325
Change subject: Reuse wfPickRandom rather than copy pasta code ...................................................................... Reuse wfPickRandom rather than copy pasta code https://gerrit.wikimedia.org/r/#/c/51322/ Change-Id: I0ce0bdb69f38f8f778e336894ed34998fc65a2a0 --- M GeoData.body.php 1 file changed, 1 insertion(+), 24 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/GeoData refs/changes/25/51325/1 diff --git a/GeoData.body.php b/GeoData.body.php index f5c1fb2..bf5fae5 100644 --- a/GeoData.body.php +++ b/GeoData.body.php @@ -165,35 +165,12 @@ * Given an array of non-normalised probabilities, this function will select * an element and return the appropriate key. * - * Borrowed from LoadBalancer - * * @param $weights array * * @return int */ public static function pickRandom( $weights ) { - if ( !is_array( $weights ) ) { - return $weights; - } - if ( count( $weights ) == 0 ) { - return false; - } - - $sum = array_sum( $weights ); - if ( $sum == 0 ) { - throw new MWException( __METHOD__ . '(): zero weight sum or no hosts specified'); - } - $max = mt_getrandmax(); - $rand = mt_rand( 0, $max ) / $max * $sum; - - $sum = 0; - foreach ( $weights as $i => $w ) { - $sum += $w; - if ( $sum >= $rand ) { - break; - } - } - return $i; + return wfPickRandom( $weights ); } /** -- To view, visit https://gerrit.wikimedia.org/r/51325 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0ce0bdb69f38f8f778e336894ed34998fc65a2a0 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/GeoData Gerrit-Branch: master Gerrit-Owner: Reedy <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
