Java Random Number getRandomNumber(int max, boolean include0)

Here you can find the source of getRandomNumber(int max, boolean include0)

Description

Returns a random number, up to the given maximum.

License

Open Source License

Declaration

public static int getRandomNumber(int max, boolean include0) 

Method Source Code

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

import java.util.Random;

public class Main {
    /**//from  ww w .jav a  2 s.  com
     * Returns a random number, up to the given maximum.
     */
    public static int getRandomNumber(int max, boolean include0) {
        Random random = new Random();

        int i = random.nextInt(max + 1);
        return (i == 0 && !include0 ? 1 : i);
    }
}

Related

  1. getRandomNumber(int len)
  2. getRandomNumber(int len)
  3. getRandomNumber(int length)
  4. getRandomNumber(int length)
  5. getRandomNumber(int length)
  6. getRandomNumber(int max, int count)
  7. getRandomNumber(int num)
  8. getRandomNumber(int randomCount)
  9. getRandomNumber(int startNumber, int endNumber)