Java generate a random integer between min and max

‮/:sptth‬/www.lautturi.com
Java generate a random integer between min and max
/**
 * @author lautturi.com 
 * Java example: random a integer between min and max in java
 */

import java.util.*;

public class Lautturi {

	public static void main(String args[]) {
		
		Random random = new Random();
		int max = 20;
		int min = 10;

		// nextInt(n) generate a integer between 0 (inclusive) and n (exclusive), 
		// so we need to add 1 to make the top value being inclusive
		
		int result = random.nextInt(max + 1 - min) + min;
		System.out.println("random integer:"+result);
	}
}
Created Time:2017-09-27 22:25:52  Author:lautturi