Here you can find the source of getRandomInt(final int maxValue)
Parameter | Description |
---|---|
maxValue | The maximum value plus one for the random value. |
public static int getRandomInt(final int maxValue)
//package com.java2s; /*/*from w w w . ja v a 2 s . c o m*/ * Copyright 2006-2014 Andy King (GreatLogic.com) * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under the License * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the License for the specific language governing permissions and limitations under * the License. */ import java.util.Random; public class Main { private static Random _random; /** * Returns a random value between 0 and the maxValue minus one. * @param maxValue The maximum value plus one for the random value. * @return A random integer between 0 (inclusive) and the specified value minus one. */ public static int getRandomInt(final int maxValue) { return _random.nextInt(maxValue); } /** * Returns a random value between a minimum and maximum value minus one. * @param minValue The minimum value for the random value. * @param maxValue The maximum value plus one for the random value. * @return A random integer between the minimum and maximum value minus one. */ public static int getRandomInt(final int minValue, final int maxValue) { return _random.nextInt(maxValue - minValue) + minValue; } }