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

doublerandomScalingFactor()
random Scaling Factor
return (double) (Math.random() > 0.5 ? 1.0 : -1.0) * Math.round(Math.random() * 100);
intrandomSeed()
Returns a a big random Integer to be used as a seed
return (int) (Math.random() * Integer.MAX_VALUE);
shortrandomShort()
Generates a random word, manipulating an internal seed which is initially set to the system time.
if (rand == 0) {
    seed ^= seed << 21;
    seed ^= seed >>> 35;
    seed ^= seed << 4;
    rand = seed;
final short s = (short) (rand & 0xffffL);
rand >>>= 16;
...
intrandomSign()
Used to get a random -1 or 1 to create numbers with random sign.
return (random.nextInt(2) << 1) - 1;
StringrandomSimpleId()
random Simple Id
return System.currentTimeMillis() + "-" + System.nanoTime();
voidrandomSleep()
random Sleep
try { 
    Thread.sleep((long) Math.abs(Math.random() * 1000));
} catch (InterruptedException e) {
    e.printStackTrace();
StringrandomStateAbbr()
random State Abbr
return STATES_ABBR[(int) (Math.random() * (STATES_ABBR.length - 1))];
byte[]randomStr(Random rnd, int size)
random Str
return randomStr(rnd, null, size, size);
voidrandomSubList(List list, int sizeOfSubList)
Using like subList() but it take randoms elements.
List<E> subList = Collections.emptyList();
if (isNotEmpty(list) && list.size() > sizeOfSubList) {
    subList = new ArrayList<E>(sizeOfSubList);
    Random generator = new Random();
    for (int i = 0; i < sizeOfSubList; i++) {
        int random = generator.nextInt(list.size());
        subList.add(list.get(random));
        list.remove(random);
...
booleanrandomSuccess()
random Success
int x = (int) (Math.random() * 100);
return x > 10;