nextInt is normally exclusive of the top value, so add 1 to make it inclusive
/** * @author lautturi.com * Java example: get a random integer within a specific range in java */ import java.util.*; import java.util.concurrent.ThreadLocalRandom; public class Lautturi { public static void main(String args[]) { Random rand = new Random(); int min = 20; int max = 100; int randomNum = ThreadLocalRandom.current().nextInt(min, max + 1); System.out.println(randomNum); } }