Java Random Int getRandomInt()

Here you can find the source of getRandomInt()

Description

Generates a new random integer

License

Open Source License

Return

random integer

Declaration

public static int getRandomInt() 

Method Source Code


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

import java.util.Random;

public class Main {
    private static final Random random = new Random();

    /**/*from  w  ww .  j  a va 2 s .c o  m*/
     * Generates a new random integer
     *
     * @return random integer
     */
    public static int getRandomInt() {
        return random.nextInt();
    }

    /**
     * Generates a new random integer between 0 (inclusive)
     * and the given maximum value (exclusive)
     *
     * @param max value (exclusive)
     * @return random integer
     */
    public static int getRandomInt(int max) {
        return random.nextInt(max);
    }

    /**
     * Generates a new random integer between the minimum
     * value (inclusive) and maximum value (exclusive)
     *
     * @param min minimum value (inclusive)
     * @param max maximum value (exclusive)
     * @return random integer
     */
    public static int getRandomInt(int min, int max) {
        return random.nextInt(max - min) + min;
    }
}

Related

  1. getIntRandom(int i)
  2. getIntRandomReqId()
  3. getIntRandomValue(int paramInt)
  4. getPositiveInt()
  5. getRandom(int c)
  6. getRandomInt()
  7. getRandomInt()
  8. getRandomInt()
  9. getRandomInt()