Here you can find the source of randomNum(int min, int max)
public static int randomNum(int min, int max)
//package com.java2s; import java.util.concurrent.ThreadLocalRandom; public class Main { public static int randomNum(int min, int max) { if (min < 0) { int i = nextInt(max + 1 + Math.abs(min)); return min + i; } else {/*w ww . j av a2 s .c om*/ int i = nextInt(max + 1 - min); return min + i; } } public static int nextInt(int val) { return nextInt(val, true); } public static int nextInt(int val, boolean isAbs) { int r = (int) (ThreadLocalRandom.current().nextDouble() * val); if (isAbs) { return Math.abs(r); } return r; } }