dépôts
/
lhc
/
web
/
wiklou.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
| inline |
side by side
(parent:
9ace77f
)
Fixed ArrayUtils::pickRandom() when $rand=0.
author
Aaron Schulz
<aschulz@wikimedia.org>
Tue, 5 Mar 2013 23:18:47 +0000
(15:18 -0800)
committer
Aaron Schulz
<aschulz@wikimedia.org>
Tue, 5 Mar 2013 23:18:47 +0000
(15:18 -0800)
Change-Id: Iba7db16a9ad08dd845fa1b4dd2bc02ffad8c5a32
includes/ArrayUtils.php
patch
|
blob
|
history
diff --git
a/includes/ArrayUtils.php
b/includes/ArrayUtils.php
index
39d43e8
..
0b74f06
100644
(file)
--- 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;
}
}