From: Aaron Schulz Date: Tue, 5 Mar 2013 23:18:47 +0000 (-0800) Subject: Fixed ArrayUtils::pickRandom() when $rand=0. X-Git-Tag: 1.31.0-rc.0~20471^2 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/journal.php?a=commitdiff_plain;h=da8ddd18f18fb7b869c4a43131fccba1f10dda00;p=lhc%2Fweb%2Fwiklou.git Fixed ArrayUtils::pickRandom() when $rand=0. Change-Id: Iba7db16a9ad08dd845fa1b4dd2bc02ffad8c5a32 --- diff --git a/includes/ArrayUtils.php b/includes/ArrayUtils.php index 39d43e87c1..0b74f06a00 100644 --- a/includes/ArrayUtils.php +++ b/includes/ArrayUtils.php @@ -58,7 +58,9 @@ class ArrayUtils { $sum = 0; foreach ( $weights as $i => $w ) { $sum += $w; - if ( $sum >= $rand ) { + # Do not return keys if they have 0 weight. + # Note that the "all 0 weight" case is handed above + if ( $w > 0 && $sum >= $rand ) { break; } }