Java Utililty Methods Random

List of utility methods to do Random

Description

The list of methods to do Random are organized into topic(s).

Method

shortrandom_g729()
randog
return (short) (0xFFFF & System.currentTimeMillis());
shortrandom_g729()
Return random short.
seed = (short) (seed * 31821L + 13849L);
return (seed);
intrandomAgain()
random Again
int r = (int) (58 * Math.random() + 65);
if (r > 90 && r < 97) {
    return randomAgain();
return r;
charrandomAlpha()
Generate a random character from the alphabet - either a-z or A-Z
int i = (int) (Math.random() * 52);
if (i > 25)
    return (char) (97 + i - 26);
else
    return (char) (65 + i);
charrandomAlternate(char c)
random Alternate
int idx = letterList.indexOf(c);
return letters[(idx + rand.nextInt(letters.length - 1) + 1) % letters.length];
char[]randomCharacterVector(int size)
Creates a random vector of chars of length size.
char[] retVal = new char[size];
for (int i = 0; i < size; i++) {
    retVal[i] = (char) ('A' + random.nextInt((int) ('Z' - 'A')));
return retVal;
StringRandomCode()
Random Code
StringBuffer str = new StringBuffer();
str.append((int) (Math.random() * 9 + 1));
for (int i = 0; i < 5; i++) {
    str.append((int) (Math.random() * 10));
return str.toString();
StringrandomCode()
random Code
int code = (int) (Math.random() * 1000);
if (code < 10) {
    return "00" + code;
} else if (code < 100) {
    return "0" + code;
} else {
    return "" + code;
LongrandomCSeq()
Generates a random long number
int cseq = (new Random()).nextInt();
if (cseq < 0)
    cseq = -cseq;
return new Long(cseq);
byte[]randomData(Random random, int length)
random Data
byte[] data = new byte[length];
random.nextBytes(data);
return data;