Java Utililty Methods Random Number

List of utility methods to do Random Number

Description

The list of methods to do Random Number are organized into topic(s).

Method

StringgetNumberedUsername(String fn, String ln)
get Numbered Username
Random r = new Random();
return fn + ln + r.nextInt(100);
intgetNumberInRange(int minimum, int maximum)
Produces a number within the specified range.
return new Random().nextInt(maximum - minimum + 1) + minimum;
longgetNumberLong()
get Number Long
return Math.abs(ran.nextLong());
StringgetNumbers()
get Numbers
Random random = new Random();
String result = random.nextInt(1000000) + "";
if (result.length() != length) {
    return getNumbers();
return result;
StringgetNumbersAndAlphabet()
get Numbers And Alphabet
Random random = new Random();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; i++) {
    sb.append(getRandomString(random.nextInt(randString.length())));
return sb.toString();
StringgetNumString(int length)
get Num String
StringBuffer sb = new StringBuffer();
for (int i = 0; i < length; i++) {
    sb.append(NUMBERCHAR.charAt(random.nextInt(NUMBERCHAR.length())));
return sb.toString();
StringgetPhoneNumber()
get Phone Number
return "0011" + getRandomNumber(9) + getRandomNumber(9) + getRandomNumber(9) + getRandomNumber(9)
        + getRandomNumber(9) + getRandomNumber(9) + getRandomNumber(9) + getRandomNumber(9)
        + getRandomNumber(9) + getRandomNumber(9);
intgetPositiveNumber(int maximum)
Gets a random positive number with specified length.
return RANDOM.nextInt(maximum) + 1;
StringgetRandNum(int charCount)
get Rand Num
String charValue = "";
for (int i = 0; i < charCount; i++) {
    char c = (char) (randomInt(0, 10) + '0');
    charValue += String.valueOf(c);
return charValue;
StringgetRandNum(int num)
get Rand Num
String res = "";
if (num < 1)
    return res;
String arr[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" };
for (int i = 0; i < num; i++) {
    Random ran = new Random();
    int index = ran.nextInt(10);
    res = res + arr[index];
...