As you use remove , you remove objects by value , not by position.
Say your list consists of the values [0, 1, 2, 3] , and you delete 0 and 1 first two times. Now you have [2, 3] whose size is 2, so you will never delete 3 now!
To remove by position, not value, say fields.remove(f) . (Note that f is an integer, and (Integer)f is an object of the type contained in the list container.)
(As an alternative to other behavior, you can continue deleting by value, but now you need to draw a random number from the [min, max] range where you need to determine the extreme values โโof the list items separately. Of course, a lot, because you will have a lot " misses "where you don't delete anything.)
source share