List of utility methods to do Random
int | getRandom(int min, int max) get Random return new Random().nextInt(max - min) + min; |
String | getRandomDigits(Random r, int l, int radix) get Random Digits StringBuilder sb = new StringBuilder(); for (int i = 0; i < l; i++) { sb.append(r.nextInt(radix)); return sb.toString(); |
T | getRandomElement(T[] items) choose a random element if (items == null) return null; int len = items.length; switch (len) { case 0: return null; case 1: return items[0]; ... |
String | getRandomFileName() Obtin un nume de fisier random String charset = "!0123456789abcdefghijklmnopqrstuvwxyz"; Random rand = new Random(System.currentTimeMillis()); int length = 10; StringBuffer sb = new StringBuffer(); for (int i = 0; i < length; i++) { int pos = rand.nextInt(charset.length()); sb.append(charset.charAt(pos)); String filename = sb.toString(); filename += "." + TRANSPOSON_EXT; return filename; |
float | getRandomFloat() Generates next random float Random rand = new Random(System.currentTimeMillis()); return rand.nextFloat(); |
float[] | getRandomFloatArray() get Random Float Array final int MAX_LENGTH = 1037; final Random random = new Random(); final float[] randomArray = new float[random.nextInt(MAX_LENGTH)]; for (int i = 0; i < randomArray.length; i++) { randomArray[i] = random.nextFloat(); return randomArray; |
Random | getRandomObject() get Random Object return rand;
|
int | getRandomPort(int low, int high) get Random Port return (int) (random.nextFloat() * (high - low)) + low; |
Long | getRandomRequestId(Integer serviceId) get Random Request Id Random r = new Random(); int index = r.nextInt(response_code.length); return 1L; |
String[] | getRandomServices(int maxSize) get Random Services Random r = new Random(); Integer size = r.nextInt(maxSize) + 1; String[] res = new String[size]; int in = 0; Integer caller_size = services.length; for (int i = 0; i < size; i++) { Integer index = r.nextInt(caller_size); res[in] = services[index]; ... |