Java Random Number getNumberInRange(int minimum, int maximum)

Here you can find the source of getNumberInRange(int minimum, int maximum)

Description

Produces a number within the specified range.

License

Open Source License

Parameter

Parameter Description
minimum The minimum number generated. Inclusive.
maximum The maximum number generated. Inclusive.

Return

Number in range [minimum] to [maximum], both inclusive.

Declaration

public static int getNumberInRange(int minimum, int maximum) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * LogicHelper.java// w  ww. ja v a2  s.  c o m
 * Copyright (c) 2014 Radix-Shock Entertainment.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl.html
 ******************************************************************************/

import java.util.Random;

public class Main {
    /**
     * Produces a number within the specified range.
     * 
     * @param minimum
     *            The minimum number generated. Inclusive.
     * @param maximum
     *            The maximum number generated. Inclusive.
     * 
     * @return Number in range [minimum] to [maximum], both inclusive.
     */
    public static int getNumberInRange(int minimum, int maximum) {
        return new Random().nextInt(maximum - minimum + 1) + minimum;
    }
}

Related

  1. getNumber(int length)
  2. getNumber(int length)
  3. getNumber(int seed)
  4. getNumberClose(int seed)
  5. getNumberedUsername(String fn, String ln)
  6. getNumberLong()
  7. getNumbers()
  8. getNumbersAndAlphabet()
  9. getNumString(int length)