Make a list of generated numbers, when your newly generated number is already in this list you make a new random number.
Random rng = new Random(); // Ideally just create one instance globally
List<Integer> generated = new ArrayList<Integer>();
for (int i = 0; i < numbersNeeded; i++)
{
while(true)
{
Integer next = rng.nextInt(max) + 1;
if (!generated.contains(next))
{
// Done for this iteration
generated.add(next);
break;
}
}
}