Java Random Int randInt(int min, int max)

Here you can find the source of randInt(int min, int max)

Description

Generates a random integer between the min and max values

License

LGPL

Parameter

Parameter Description
min The smallest possible number
max The largest possible number

Return

A random number between the min and max parameters

Declaration

public static int randInt(int min, int max) 

Method Source Code


//package com.java2s;
//License from project: LGPL 

import java.util.Random;

public class Main {
    /**//from   ww w  .ja va  2  s  .  co  m
     * Generates a random integer between the min and max values
     *
     * @param min The smallest possible number
     * @param max The largest possible number
     * @return A random number between the min and max parameters
     */
    public static int randInt(int min, int max) {
        Random rand = new Random();
        return rand.nextInt(max - min + 1) + min;
    }
}

Related

  1. randInt(int max)
  2. randint(int max)
  3. randInt(int min, int max)
  4. randInt(int min, int max)
  5. randInt(int min, int max)
  6. randInt(int min, int max)
  7. randInt(int min, int max)
  8. randInt(int min, int max)
  9. randInt(int min, int max)