Java Utililty Methods Random Long

List of utility methods to do Random Long

Description

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

Method

longrandomLong(long x, long y)
random Long
return x + ((long) (Math.random() * (y - x)));
longrandomLongWithMinMax(long min, long max)
random Long With Min Max
return (long) (min + (Math.random() * (max - min + 1)));
voidrandomSleep(long ms)
Sleep for a short random amount of time
try {
    Thread.sleep((long) (ms * Math.random()));
} catch (InterruptedException e) {
StringrandomStr(long strLen)
random Str
char freshChar;
String freshString;
freshString = "";
while (freshString.length() < (strLen - 1)) {
    freshChar = (char) (Math.random() * 128);
    if (Character.isLetter(freshChar)) {
        freshString += freshChar;
return (freshString);
StringrandomStr(long strLen)
This is slow!
char freshChar;
StringBuilder sb = new StringBuilder();
while (sb.length() < (strLen - 1)) {
    freshChar = (char) (Math.random() * 128);
    if (Character.isLetter(freshChar)) {
        sb.append(freshChar);
return sb.toString();
longrandPosLong()
simply uses Math.random, only 0 and positive longs returned
return randPosLong(Long.MAX_VALUE);
longsecureRandomLong()
secure Random Long
return UUID.randomUUID().getLeastSignificantBits();