Java Random Number getRandomNumber(int len)

Here you can find the source of getRandomNumber(int len)

Description

get Random Number

License

Open Source License

Declaration

public static String getRandomNumber(int len) 

Method Source Code

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

import java.util.Random;

public class Main {
    private static char[] m_chars = { '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'E', 'F', 'G', 'H', 'J',
            'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'V', 'W', 'X', 'Y' };
    private static Random m_ran = new Random();

    public static String getRandomNumber(int len) {
        StringBuffer sb = new StringBuffer();
        int p;//from   w  ww  .j a v  a2s.  co m
        for (int i = 0; i < len; i++) {
            p = getRandomInt(0, m_chars.length);
            if (p < 0)
                p = 0;
            if (p >= m_chars.length)
                p = m_chars.length - 1;
            sb.append(m_chars[p]);
        }
        return sb.toString();
    }

    public static int getRandomInt(int lo, int hi) {
        return lo + (int) ((hi - lo + 1) * m_ran.nextFloat());
    }
}

Related

  1. getRandomNumber(final int maxInt, final int minInt)
  2. getRandomNumber(int bit)
  3. getRandomNumber(int bound)
  4. getRandomNumber(int digit)
  5. getRandomNumber(int len)
  6. getRandomNumber(int length)
  7. getRandomNumber(int length)
  8. getRandomNumber(int length)
  9. getRandomNumber(int max, boolean include0)