Java Random Number getRandomNum(int pwd_len)

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

Description

get Random Num

License

Open Source License

Declaration

public static String getRandomNum(int pwd_len) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Random;

public class Main {
    public static String getRandomNum(int pwd_len) {
        String randomStr = "abcdefghijklmnopqrstuvwxyz0123456789";
        final int maxNum = 36;
        int i;//  w w w .  j  av a2s .  co  m
        int count = 0;
        char[] str = randomStr.toCharArray();
        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. getRandomNum()
  2. getRandomNum()
  3. getRandomNum()
  4. getRandomNum(double pSngBegin, double pSngEnd)
  5. getRandomNum(int len)
  6. getRandomNumAndLetterAF(int len)
  7. getRandomNumAndStr(int length)
  8. getRandomNumber()
  9. getRandomNumber()