ShortList implements Serializable { public short removeRandom(MersenneTwisterFast random) { int randomIndex = random.nextInt(size); short temp = data[randomIndex]; size--; data[randomIndex] = data[size]; return temp; } ShortList(int capacity); void add(short key); void addIfNotPresent(short key); int capacity(); void clear(); boolean contains(short key); void copyDataFrom(ShortList that); short get(int i); short removeLast(); short removeRandom(MersenneTwisterFast random); void set(int i, short key); int size(); @Override String toString(); String toString(CoordinateSystem coords); void addAll(ShortSet set);  }
@Test public void testRemoveRandom() { list.add((short)5); list.add((short)8); list.add((short)3); int firstSize = list.size(); int random = list.removeRandom(new MersenneTwisterFast()); assertEquals(firstSize - 1, list.size()); assertTrue((random == (short)5) || (random == (short)8) || (random == (short)3)); }