Java Random Int randomInt(final int min, final int max)

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

Description

Generate random integer over range specified by min and max, inclusively.

License

BSD License

Parameter

Parameter Description
min Low value in range
max High value in range

Return

A random integer

Declaration

public static int randomInt(final int min, final int max) 

Method Source Code

//package com.java2s;
/*L//from  ww w  . j  a v  a 2s .co  m
 *  Copyright RTI International
 *
 *  Distributed under the OSI-approved BSD 3-Clause License.
 *  See http://ncip.github.com/webgenome/LICENSE.txt for details.
 */

public class Main {
    /**
     * Generate random integer over range specified by <code>min</code>
     * and <code>max</code>, inclusively.
     * @param min Low value in range
     * @param max High value in range
     * @return A random integer
     */
    public static int randomInt(final int min, final int max) {
        return min + (int) (Math.random() * (double) (max - min));
    }
}

Related

  1. randomHex(int length)
  2. randomHexOfInt(int min, int max)
  3. randomInIntervall(float low, float high)
  4. randomInt(double arg)
  5. randomInt(final int max)
  6. randomInt(final int upToNotInclusive)
  7. randomInt(int ceil)
  8. randomInt(int fromInclusive, int toExclusive)
  9. randomInt(int in)