Create a list if all numbers in the range, then shuffle the list:
List<Integer> numbers = new ArrayList<>();
// eg for range 3-5
for (int i = 3; i <= 5; i++)
numbers.add(i);
Collections.shuffle(numbers);
Now use them in their new (random) order.
Unless your range is very large (millions) this will work fine.
Java8 version:
List<Integer> numbers = IntStream.rangeClosed(3, 5).boxed().collect(Collectors.toList());
Collections.shuffle(numbers);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…