Here you can find the source of getNumberInRange(int minimum, int maximum)
Parameter | Description |
---|---|
minimum | The minimum number generated. Inclusive. |
maximum | The maximum number generated. Inclusive. |
public static int getNumberInRange(int minimum, int maximum)
//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; } }