I am trying to work out how to add 6 randomly generated numbers to a HashSet. I am getting results but they are inconsistent. Sometimes it prints 6 numbers to the console and other times it prints 5 numbers to the console.
I'm new to this stuff only this morning so I apologize if it is blatantly obvious and thank you for your help.
HashSet<Integer> generatedLotteryNumbers = new HashSet<Integer>();
Random r = new Random();
for(int i=0; i<6; i++){
generatedLotteryNumbers.add(r.nextInt(49));
}
System.out.println(generatedLotteryNumbers);