Java Random Number getRandomNumber(int bound)

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

Description

Produces a random number in the interval (-bound, bound)

License

Open Source License

Parameter

Parameter Description
bound specifies the interval from which to chose the number

Return

a random number in the interval (-bound, bound)

Declaration

public static int getRandomNumber(int bound) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Random;

public class Main {
    public final static Random RANDOM = new Random();

    /**/*w w w.  j a va  2  s .  co  m*/
     * Produces a random number in the interval (-bound, bound)
     * @param bound specifies the interval from which to chose the number
     * @return a random number in the interval (-bound, bound)
     */
    public static int getRandomNumber(int bound) {
        return (RANDOM.nextInt(1) * 2 - 1) * RANDOM.nextInt(bound);
    }
}

Related

  1. getRandomNumber()
  2. getRandomNumber()
  3. getRandomNumber(final int from, final int to)
  4. getRandomNumber(final int maxInt, final int minInt)
  5. getRandomNumber(int bit)
  6. getRandomNumber(int digit)
  7. getRandomNumber(int len)
  8. getRandomNumber(int len)
  9. getRandomNumber(int length)