2
I have an Arraylist with N items inside and I need to randomly group them into 2 sets of X items and the rest into another set. But none of them can repeat themselves.
For example: my Arraylist has 20 items added and I want to divide it into 2 groups of 7 and the remaining 6 into another set. Only, the choice of these items to compose the sets has to be random (Random) and none of these 20 can be repeated in any of the sets.
I have knowledge of the Random class and am using it, but the problem is to compare the new numbers generated with the previous ones, so there are no repeats.
Eduardo, is this what you were looking for? It solves your problem?
– ramaral
Thank you very much for your reply, Ramaral. I did something similar to yours (extract from a main array and divide it into the desired number of sets). Only I did it using Random even, but your version is much leaner and cleaner. Thanks again and congratulations!
– Eduardo
Glad I could help and welcome to Stackoverflow. See here how to proceed when a reply has been useful to you.
– ramaral