From da8ddd18f18fb7b869c4a43131fccba1f10dda00 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Tue, 5 Mar 2013 15:18:47 -0800 Subject: [PATCH] Fixed ArrayUtils::pickRandom() when $rand=0. Change-Id: Iba7db16a9ad08dd845fa1b4dd2bc02ffad8c5a32 --- includes/ArrayUtils.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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; } } -- 2.20.1