// generate a int value between 0(inclusive) and bound(exclusive); rand.nextInt(int bound); // get a random value between min and max int randomNum = random.nextInt(max + 1 - min) + min;
/**
* @author lautturi.com
* Java example: generate a random int value from 1 to 100 in java
*/
import java.util.*;
public class Lautturi {
public static void main(String[] args) {
Random random = new Random();
int min = 1;
int max = 100;
int randomNum = random.nextInt(max + 1 - min) + min;
System.out.println("random number:"+randomNum);
}
}