Fixed my own retarded (broken) implementation of pickRandom. If a list
had been passed in with 3 elements and the first one was the 'skip', then the second one would get picked 100% of the time. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3730 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -170,15 +170,17 @@ public class RandomUtil
|
|||||||
int size = values.size();
|
int size = values.size();
|
||||||
if (size < 2) {
|
if (size < 2) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Must have at least one element [size=" + size + "]");
|
"Must have at least two elements [size=" + size + "]");
|
||||||
}
|
}
|
||||||
|
|
||||||
int pick = getInt(size - 1);
|
int pick = getInt(size - 1);
|
||||||
Object val = values.get(pick);
|
for (int ii = 0; ii < size; ii++) {
|
||||||
if (val == skip) {
|
Object val = values.get(ii);
|
||||||
val = values.get(pick + 1);
|
if ((val != skip) && (pick-- == 0)) {
|
||||||
|
return val;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return val;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user