9
0
mirror of https://github.com/VolmitSoftware/Iris.git synced 2025-12-28 11:39:07 +00:00
This commit is contained in:
Daniel Mills
2021-07-31 22:32:14 -04:00
parent 9a11021560
commit 6b97acdb50
12 changed files with 204 additions and 97 deletions

View File

@@ -472,6 +472,18 @@ public class KList<T> extends ArrayList<T> implements List<T> {
return remove(M.irand(0, last()));
}
public T popRandom(RNG rng) {
if (isEmpty()) {
return null;
}
if (size() == 1) {
return pop();
}
return remove(rng.i(0, last()));
}
public static KList<String> fromJSONAny(JSONArray oo) {
KList<String> s = new KList<String>();
@@ -613,6 +625,23 @@ public class KList<T> extends ArrayList<T> implements List<T> {
return get(M.irand(0, last()));
}
public KList<T> popRandom(RNG rng, int c)
{
KList<T> m = new KList<>();
for(int i = 0; i < c; i++)
{
if(isEmpty())
{
break;
}
m.add(popRandom());
}
return m;
}
public T getRandom(RNG rng) {
if (isEmpty()) {
return null;