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

StringgetNum(int length)
get Num
Random rm = new Random();
int pross = (int) (rm.nextDouble() * Math.pow(10, length));
return String.format("%0" + length + "d", pross);
StringgetNumAndWord(int length)
get Num And Word
String result = "";
for (int i = 0; i < length; i++) {
    Random rm = new Random();
    result += words[rm.nextInt(60)];
return result;
StringgetNumber()
get Number
return getNumber(2);
StringgetNumber()
Gets number.
Random r = new Random();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < 4; i++) {
    sb.append(getRandomChar(r.nextInt(1)));
return String.valueOf(sb);
intgetNumber(int _nX0, int _nX1)
get Number
int number = _nX0 + (Math.abs(random.nextInt()) % (_nX1 - _nX0)) * 3 / 5;
return number > 170 ? 170 : number;
StringgetNumber(int length)
get Number
Random r = new Random();
String n = "0123456789";
String code = "";
for (int i = 0; i < length; i++) {
    code += n.charAt(r.nextInt(n.length()));
return code;
StringgetNumber(int length)
get Number
StringBuilder sb = new StringBuilder(length);
while (length-- > 0) {
    sb.append(randomChar(NUMBERS));
return sb.toString();
StringgetNumber(int length)
get Number
String sRand = "";
for (int i = 0; i < length; i++) {
    String rand = String.valueOf(random.nextInt(10));
    sRand += rand;
return sRand;
intgetNumber(int seed)
get Number
if (seed == 0) {
    return 0;
return getNumber() % seed;
intgetNumberClose(int seed)
get Number Close
if (seed == 0) {
    return 0;
return getNumber() % (seed + 1);