Java Random Int randInt(int max)

Here you can find the source of randInt(int max)

Description

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.

License

Apache License

Parameter

Parameter Description
max exclusive

Return

the result

Declaration

public static final int randInt(int max) 

Method Source Code

//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;
    }
}

Related

  1. randInRangeInc(int min, int max)
  2. randInt()
  3. randInt()
  4. randInt(int l)
  5. randInt(int low, int high)
  6. randint(int max)
  7. randInt(int min, int max)
  8. randInt(int min, int max)
  9. randInt(int min, int max)