Java Random Number getRandomNumberInRange(Random random, int min, int max)

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

Description

Returns a random number between min and max, inclusive.

License

Open Source License

Parameter

Parameter Description
random The random number generator.
min The minimum value.
max The maximum value.

Return

A random number between min and max, inclusive.

Declaration

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

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Random;

public class Main {
    /**/*  w w w . ja v  a 2  s.  co  m*/
     * Returns a random number between min and max, inclusive.
     *
     * @param random The random number generator.
     * @param min    The minimum value.
     * @param max    The maximum value.
     * @return A random number between min and max, inclusive.
     */
    public static int getRandomNumberInRange(Random random, int min, int max) {
        return min + random.nextInt(max - min + 1);
    }
}

Related

  1. getRandomNumber(int randomCount)
  2. getRandomNumber(int startNumber, int endNumber)
  3. getRandomNumberBetween(int min, int max)
  4. getRandomNumberFixLength()
  5. getRandomNumberGenerator()
  6. getRandomNumbers(int range, int count, Random rnd)
  7. getRandomNumberString(int length)
  8. getRandomNumer(int length)
  9. getRandomNumericString(int maxlen)