Here you can find the source of getRandomInteger(int min, int max)
Parameter | Description |
---|---|
min | The minimum value (>= 0). |
max | The maximum value (>= 0 && >= min). |
public static int getRandomInteger(int min, int max)
//package com.java2s; /*/* w w w. j av a2 s. com*/ * Copyright (C) 2013-2014 Byron 3D Games Studio (www.b3dgs.com) Pierre-Alexandre (contact@b3dgs.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import java.util.Random; public class Main { /** The random utility instance. */ private static final Random RANDOM = new Random(); /** * Get a random integer value from 0 and 2^32. * * @return A value between 0 and 2^32. */ public static int getRandomInteger() { return RANDOM.nextInt(); } /** * Get a random value from 0 and a maximum. * * @param max The maximum randomized value. * @return A value between 0 inclusive and max inclusive. */ public static int getRandomInteger(int max) { return RANDOM.nextInt(max + 1); } /** * Get a random value from an interval. * * @param min The minimum value (>= 0). * @param max The maximum value (>= 0 && >= min). * @return A value between min inclusive and max inclusive. */ public static int getRandomInteger(int min, int max) { return min + RANDOM.nextInt(max + 1 - min); } }