0
how to create a function that can return a linkedList with 4 random nombers and those nombers dont be repeated ?
thank for who while help me
1 Réponse
+ 1
Inside your method, create a LinkedList.
Create a while-loop that runs while list.size() < 4 .
random.nextInt() a fresh random number, and if(!list.contains(thatNumber)) , list.add(thatNumber) .
Maybe you are better off using a Set (a HashSet), because uniqueness is the Set's Feature: you could skip the if-clause and just add stuff until the size of the set is good.