Aaron Schulz has uploaded a new change for review. https://gerrit.wikimedia.org/r/51820
Change subject: Fixed edge case in wfPickRandom() were a 0 weighted item can be picked. ...................................................................... Fixed edge case in wfPickRandom() were a 0 weighted item can be picked. Change-Id: I6c2cac9f7446437f98da838a9354ee1937c9b423 --- M includes/GlobalFunctions.php 1 file changed, 4 insertions(+), 6 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/20/51820/1 diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 79a4920..1ec3488 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -344,14 +344,12 @@ $sum = array_sum( $weights ); if ( $sum == 0 ) { - # No loads on any of them - # In previous versions, this triggered an unweighted random selection, - # but this feature has been removed as of April 2006 to allow for strict - # separation of query groups. - return false; + return false; // no load on any item (and avoid infinite loop below) } $max = mt_getrandmax(); - $rand = mt_rand( 0, $max ) / $max * $sum; + do { + $rand = mt_rand( 0, $max ) / $max * $sum; + } while ( $rand == 0 ); // don't let a 0 weighted item be picked $sum = 0; foreach ( $weights as $i => $w ) { -- To view, visit https://gerrit.wikimedia.org/r/51820 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6c2cac9f7446437f98da838a9354ee1937c9b423 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Aaron Schulz <asch...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits