Java examples for java.util:Random Int
Generates random integer from a range
//package com.java2s; import java.util.Random; public class Main { public static void main(String[] argv) throws Exception { int min = 2; int max = 2; System.out.println(getRandomNum(min, max)); }/* w ww. jav a 2 s. c o m*/ /** * Generates random integer from a range * * @param min * @param max * @return - random integer */ public static int getRandomNum(int min, int max) { return new Random().nextInt((max - min) + 1) + min; } }