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

StringgetRandNum(int num)
get Rand Num
String randnum = "";
for (int i = 0; i < num; i++) {
    Random rand = new Random();
    randnum += rand.nextInt(10);
return randnum;
intgetRandNumber(int maxNumber)
get Rand Number
return rand.nextInt(maxNumber);
doublegetRandomDouble(double max, String decimalFormat)
get Random Double
DecimalFormat formatter = new DecimalFormat(decimalFormat);
return Double.parseDouble(formatter.format(Math.random() * max));
longgetRandomNum()
Return a random long number.
final Random generator = new Random();
return generator.nextLong();
intgetRandomNum()
get integer random number
return rnd.nextInt();
StringgetRandomNum()
get Random Num
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssS");
Date now = new Date();
String s = sdf.format(now);
Random rd = new Random();
int rdNum = rd.nextInt(1000);
String subDir = s + String.valueOf(rdNum);
return subDir;
StringgetRandomNum()
get Random Num
StringBuffer sb = new StringBuffer();
sb.append(dataToString(new java.util.Date(), DATE_FORMAT_YYYYMMDDHHMM));
sb.append(String.valueOf(Math.round(Math.random() * 8999 + 1000)));
return sb.toString();
doublegetRandomNum(double pSngBegin, double pSngEnd)
get Random Num
if (pSngEnd < pSngBegin) {
    throw new IllegalArgumentException("pSngEnd must not smaller than pSngBegin");
return (pSngEnd - pSngBegin) * Math.random() + pSngBegin;
StringgetRandomNum(int len)
get Random Num
Random random = new Random();
StringBuffer strNum = new StringBuffer();
for (int i = 0; i < len; i++) {
    int num = random.nextInt(10);
    strNum.append(num);
return strNum.toString();
StringgetRandomNum(int pwd_len)
get Random Num
String randomStr = "abcdefghijklmnopqrstuvwxyz0123456789";
final int maxNum = 36;
int i;
int count = 0;
char[] str = randomStr.toCharArray();
StringBuffer pwd = new StringBuffer("");
Random r = new Random();
while (count < pwd_len) {
...