Here you can find the source of randomIntInRange(int lowerBound, int upperBound)
public static int randomIntInRange(int lowerBound, int upperBound)
//package com.java2s; //License from project: Open Source License public class Main { public static int randomIntInRange(int lowerBound, int upperBound) { if (upperBound < lowerBound) throw new IllegalArgumentException("lowerBound must be smaller than upperBound"); if (upperBound == lowerBound) return upperBound; double rand = Math.random(); rand = rand * (upperBound - lowerBound); rand += lowerBound;//from ww w .ja va 2 s . co m float r = (float) rand; return Math.round(r); } }