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

intgetRandomPortNumber()
Returns a random local port number that user applications could bind to.
return getRandomPortNumber(MIN_PORT_NUMBER, MAX_PORT_NUMBER);
intgetRandonNumber(int range)
get Randon Number
return randomNumber(range);
Stringgetrannumber()
getrannumber
StringBuffer strbufguess = new StringBuffer();
String strguess = new String();
int[] nums = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
Random rannum = new Random();
int count;
int i = 0, temp_i = 0;
for (int j = 10; j > 4; j--) {
    i = 0;
...
StringgetRndNumByLen(int lengthOfNumber)
generate specified length string with numbers.
int i, count = 0;
StringBuffer randomStr = new StringBuffer("");
Random rnd = new Random();
while (count < lengthOfNumber) {
    i = Math.abs(rnd.nextInt(9));
    if (i == 0 && count == 0) {
    } else {
        randomStr.append(String.valueOf(i));
...
StringgetSerialNumber(int length)
get Serial Number
StringBuffer stringBuffer = new StringBuffer();
Random random = new Random();
for (int i = 1; i <= length; i++) {
    stringBuffer.append(random.nextInt(9) + 1);
return stringBuffer.toString();
StringgetTenByteNumber()
get Ten Byte Number
String tenByte = "";
for (int i = 0; i < 10; i++) {
    tenByte = tenByte + rd.nextInt(9);
return tenByte;
StringrandomHexNumber(final int length)
random Hex Number
char[] randBuffer = new char[length];
for (int i = 0; i < randBuffer.length; i++) {
    randBuffer[i] = hexNumbers[randGen.nextInt(15)];
return (new String(randBuffer));
StringrandomNumber(int length)
random Number
StringBuffer sb = new StringBuffer();
for (int loop = 0; loop < length; ++loop) {
    sb.append(digits[rand.nextInt(digits.length)]);
return sb.toString();
intrandomNumber(int min, int max, Random r)
random Number
return (int) (r.nextDouble() * (max - min + 1) + min);
int[]randperm(int number)
randperm
int[] array = new int[number];
for (int i = 0; i < number; i++)
    array[i] = i;
int index, temp;
Random random = new Random();
for (int i = number; i > 1; i--) {
    index = random.nextInt(i);
    temp = array[i - 1];
...