I have generated a list of 20 unique random numbers between 1 and 300, and used that for what I need to use it for. However, I also need the numbers that have not made it to the list to be added into another list for use in another function.
Here is the code I have used to generate the random list of 20 numbers:
JToggleButton[][] p = new JToggleButton[5][4];
ArrayList<Integer> list = new ArrayList<Integer>();
Random rand = new Random();
for (int i = 0; i < p.length; i++) {
for (int j = 0; j < p[i].length; j++) {
int randomNum = rand.nextInt((300 - 1) + 1) + 1;
while (list.contains(randomNum)) {
randomNum = rand.nextInt((300 - 1) + 1) + 1;
}
list.add(randomNum);
// rest of code that I need the random number list for
I need to get the other 280 numbers not included in this 20 item list into another list, but I am unsure how to actually get these 'unused' numbers
Aucun commentaire:
Enregistrer un commentaire