Java Random Number getPositiveNumber(int maximum)

Here you can find the source of getPositiveNumber(int maximum)

Description

Gets a random positive number with specified length.

License

Open Source License

Parameter

Parameter Description
maximum the maximum of the number.

Return

random number with specified maximum.

Declaration

public static int getPositiveNumber(int maximum) 

Method Source Code


//package com.java2s;
import java.util.Random;

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

    /**/*  w  ww  . j  a  v  a 2 s . c  o m*/
     * Gets a random positive number with specified length.
     *
     * @param maximum the maximum of the number.
     * @return random number with specified maximum.
     */
    public static int getPositiveNumber(int maximum) {
        return RANDOM.nextInt(maximum) + 1;
    }
}

Related

  1. getNumberLong()
  2. getNumbers()
  3. getNumbersAndAlphabet()
  4. getNumString(int length)
  5. getPhoneNumber()
  6. getRandNum(int charCount)
  7. getRandNum(int num)
  8. getRandNum(int num)
  9. getRandNumber(int maxNumber)