Java Random Number genRandomNum(int pwd_len)

Here you can find the source of genRandomNum(int pwd_len)

Description

gen Random Num

License

Open Source License

Declaration

public static String genRandomNum(int pwd_len) 

Method Source Code


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

public class Main {

    public static String genRandomNum(int pwd_len) {
        final int maxNum = 36;
        int i;/* w ww .  jav  a2 s .c om*/
        int count = 0;
        char[] str = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' };
        StringBuffer pwd = new StringBuffer("");
        Random r = new Random();
        while (count < pwd_len) {
            i = Math.abs(r.nextInt(maxNum));
            if (i >= 0 && i < str.length) {
                pwd.append(str[i]);
                count++;
            }
        }
        return pwd.toString();
    }
}

Related

  1. generateRandomNumber(int min, int max)
  2. generateRandomNumber(int start, int end)
  3. generateRandomNumberBetween(final int low, final int high)
  4. generateRandomNumericString(int maxLength)
  5. generateSaltNumber()
  6. genRandomNumber()
  7. genRandomNumber(int begin, int end)
  8. genRandomNumber(int digitNumber)
  9. genRandomNumber(int minNumber, int maxNumber, int digits)