Here you can find the source of randInt(int max)
Parameter | Description |
---|---|
max | exclusive |
public static final int randInt(int max)
//package com.java2s; /**// ww w . jav a 2s .c om * MockUtil.java * * Copyright 2011 Niolex, Inc. * * Niolex licenses this file to you 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 generator = new Random(); /** * Generate a random int uniformly distributed int value between 0 (inclusive) and the specified value * (exclusive), drawn from the inner random number generator's sequence. * * @param max exclusive * @return the result */ public static final int randInt(int max) { return generator.nextInt(max); } /** * Generate a random int uniformly distributed int value between <code>from (inclusive)</code> and <code>to</code> * (exclusive), drawn from the inner random number generator's sequence. * * @param from inclusive * @param to exclusive * @return the result */ public static final int randInt(int from, int to) { return generator.nextInt(to - from) + from; } }