Java Random Int getRandomInt(int min, int max, Random random)

Here you can find the source of getRandomInt(int min, int max, Random random)

Description

Get a random int value in given range

License

Open Source License

Parameter

Parameter Description
min range start
max range end
random the Random object to random with

Return

an int value in the given range

Declaration

public static int getRandomInt(int min, int max, Random random) 

Method Source Code


//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;
    }
}

Related

  1. getRandomInt(int max)
  2. getRandomInt(int max)
  3. getRandomInt(int max)
  4. getRandomInt(int min, int max)
  5. getRandomInt(int min, int max)
  6. getRandomInt(int minimum, int maximum)
  7. getRandomInt(int sek, int min, int max)
  8. getRandomInt(int size)
  9. getRandomInt(Random rand, int lower, int upper)