Java generate a random integer in a range

https:/‮l.www/‬autturi.com
Java generate a random integer in a range

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);
	}
}
Created Time:2017-09-27 22:19:59  Author:lautturi