int max = 45; int min = 30; Random random = new Random(); int result = random.nextInt(max) % (max - min + 1) + min;