Here you can find the source of getRandomInt(int min, int max, Random random)
Parameter | Description |
---|---|
min | range start |
max | range end |
random | the Random object to random with |
public static int getRandomInt(int min, int max, Random random)
//package com.java2s; import java.util.Random; public class Main { /**//from ww w.ja va 2 s . c om * Get a random int value in given range * * @param min range start * @param max range end * @param random the Random object to random with * @return an int value in the given range */ public static int getRandomInt(int min, int max, Random random) { int diff = max - min + 1; int randomInt = random.nextInt(diff); return randomInt + min; } }