Java Random String getRandomNumberString(int maxValue, int strLen)

Here you can find the source of getRandomNumberString(int maxValue, int strLen)

Description

get Random Number String

License

Apache License

Declaration

public static String getRandomNumberString(int maxValue, int strLen) 

Method Source Code

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

import java.util.*;

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

    public static String getRandomNumberString(int maxValue, int strLen) {
        return intPadString(rnd.nextInt(maxValue), strLen);
    }//from  w w  w .ja  v a 2s  .c  o m

    public static String intPadString(int num, int strLen) {
        return leftPadString(String.valueOf(num), '0', strLen);
    }

    public static String leftPadString(String str, char pad, int length) {
        if (str.length() >= length)
            return str;
        StringBuffer sb = new StringBuffer();
        while (sb.length() < length - str.length())
            sb.append(pad);
        sb.append(str);
        return sb.toString();
    }
}

Related

  1. getRandomAString(int min, int max)
  2. getRandomColors(final int size, final List colors)
  3. getRandomElementOrCompound(String equation)
  4. getRandomFromTier(int tier, String lvlRange)
  5. getRandomNumberString(int length)
  6. getRandomNumberStringBase36(int strLen)
  7. getRandomStr()
  8. getRandomStr()
  9. getrandomstr()