List of utility methods to do Random
double | randomScalingFactor() random Scaling Factor return (double) (Math.random() > 0.5 ? 1.0 : -1.0) * Math.round(Math.random() * 100); |
int | randomSeed() Returns a a big random Integer to be used as a seed return (int) (Math.random() * Integer.MAX_VALUE); |
short | randomShort() 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; ... |
int | randomSign() Used to get a random -1 or 1 to create numbers with random sign. return (random.nextInt(2) << 1) - 1;
|
String | randomSimpleId() random Simple Id return System.currentTimeMillis() + "-" + System.nanoTime(); |
void | randomSleep() random Sleep try { Thread.sleep((long) Math.abs(Math.random() * 1000)); } catch (InterruptedException e) { e.printStackTrace(); |
String | randomStateAbbr() 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);
|
void | randomSubList(List 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); ... |
boolean | randomSuccess() random Success int x = (int) (Math.random() * 100); return x > 10; |