Java Random Int getRandomInt(int bound)

Here you can find the source of getRandomInt(int bound)

Description

get a random number

License

Apache License

Parameter

Parameter Description
bound the upper bound (exclusive). Must be positive.

Return

an int value between zero (inclusive) and bound (exclusive)

Declaration

public static int getRandomInt(int bound) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.util.Random;

public class Main {
    /**/* w  w w.  j ava 2s. co m*/
     * get a random number
     *
     * @param bound the upper bound (exclusive).  Must be positive.
     * @return an {@code int} value between zero (inclusive) and {@code bound} (exclusive)
     */
    public static int getRandomInt(int bound) {
        Random random = new Random();
        return random.nextInt(bound);
    }
}

Related

  1. getRandomInt()
  2. getRandomInt(final int limit)
  3. getRandomInt(final int max)
  4. getRandomInt(final int maxValue)
  5. getRandomInt(final int min, final int max, final Random random)
  6. getRandomInt(int intStart, int intEnd)
  7. getRandomInt(int lower, int upper)
  8. getRandomInt(int lower, int upper)
  9. getRandomInt(int max)