This question already has an answer here:
- Generating Unique Random Numbers in Java 12 answers
I need to get code that will allow me to remove duplicates of numbers as I have a random number generator which generates number associated to the counter of an array, the array being a 'pack' of cards, so I can't really afford to change the code but I really need to stop duplicates appearing!
for (int v = 0; v < 30; v++)
{
Random rnd = new Random();
rnd.nextInt(30);
int i = rnd.nextInt(30);
System.out.println(i + " " + aCards[i].getCard());
}
This is what the code above produces, there are clearly duplicates within the list!
Aucun commentaire:
Enregistrer un commentaire