Below code will help you to generate random numbers between two numbers in the given range:
private void generateRandomNumbers(int min, int max) {
// min & max will be changed as per your requirement. In my case, I've taken min = 2 & max = 32
int randomNumberCount = 10;
int dif = max - min;
if (dif < (randomNumberCount * 3)) {
dif = (randomNumberCount * 3);
}
int margin = (int) Math.ceil((float) dif / randomNumberCount);
List<Integer> randomNumberList = new ArrayList<>();
Random random = new Random();
for (int i = 0; i < randomNumberCount; i++) {
int range = (margin * i) + min; // 2, 5, 8
int randomNum = random.nextInt(margin);
if (randomNum == 0) {
randomNum = 1;
}
int number = (randomNum + range);
randomNumberList.add(number);
}
Collections.sort(randomNumberList);
Log.i("generateRandomNumbers", "RandomNumberList: " + randomNumberList);
}