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

StringgenerateRandomnumber(int firstNum, int restNum)
generate Randomnumber
Random random = new Random(System.currentTimeMillis());
String first = String.valueOf(random.nextInt(firstNum));
String rest = String.valueOf(random.nextInt(restNum));
return first + rest;
intgenerateRandomNumber(int from, int to)
Generates random number in given range.
return r.nextInt(to - from + 1) + from;
StringgenerateRandomNumber(int length)
generate Random Number
Random random = new Random();
String val = "";
for (int i = 0; i < length; i++) {
    val += String.valueOf(random.nextInt(10));
return val;
intgenerateRandomNumber(int min, int max)
generate Random Number
return (int) (min + (Math.random() * ((max - min) + 1)));
intgenerateRandomNumber(int min, int max)
Generates a random number in the range [min, max]
return min + (int) (Math.random() * ((max - min) + 1));
intgenerateRandomNumber(int start, int end)
Generates the random number within the range.
double randomValue = Math.random();
int randomNumber = (int) (start + Math.round(randomValue * (end - start)));
return randomNumber;
intgenerateRandomNumberBetween(final int low, final int high)
generate Random Number Between
return low + new Random().nextInt(high - low);
StringgenerateRandomNumericString(int maxLength)
generate Random Numeric String
Random random = new Random();
Long number = new Long((Math.round(Math.random() * maxLength)));
return number.toString();
StringgenerateSaltNumber()
generate Salt Number
Random random = new Random(System.nanoTime());
StringBuilder saltNumber = new StringBuilder();
for (byte i = 0; i < SALT_NUMBER_SIZE; i++) {
    saltNumber.append(random.nextInt(10));
return saltNumber.toString();
StringgenRandomNum(int pwd_len)
gen Random Num
final int maxNum = 36;
int i;
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));
...