Fixed ArrayUtils::pickRandom() when $rand=0.

Change-Id: Iba7db16a9ad08dd845fa1b4dd2bc02ffad8c5a32
This commit is contained in:
Aaron Schulz 2013-03-05 15:18:47 -08:00
parent 9ace77f03c
commit da8ddd18f1

View file

@ -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;
}
}