List of utility methods to do Random
String | createRandomStr(int digit) create Random Str String base = "abcdefghijklmnopqrstuvwxyz0123456789"; int baseLength = base.length(); Random random = new Random(); StringBuilder stringBuilder = new StringBuilder(); for (int i = 0; i < digit; i++) { int number = random.nextInt(baseLength); stringBuilder.append(base.charAt(number)); return stringBuilder.toString(); |
String | decimal_random() decimarandom String valor_retorno = new String(""); int[] ndigitos = new int[10]; int n; Random rnd = new Random(); for (int i = 0; i < 10; i++) ndigitos[i] = 0; for (long i = 0; i < 100000L; i++) { n = (int) (rnd.nextDouble() * 10.0); ... |
boolean | equalsRandomIterable(List> a, List> bl) equals Random Iterable Iterator<?> it = bl.iterator(); for (Object anA : a) { if (it.hasNext()) { Object o2 = it.next(); if (anA == o2) continue; if (anA == null) return false; ... |
K | extractRandomObject(Collection extract Random Object if (c == null || c.size() == 0) return null; int randomIndex = (int) (Math.random() * c.size()); Iterator<K> iter = c.iterator(); K o = iter.next(); while (iter.hasNext() && randomIndex-- > 0) o = iter.next(); return o; ... |
Vector | extractRandomVector(Collection extract Random Vector Vector cropped = new Vector(); if (c == null || c.size() < 1 || newSize < 1) return cropped; int s = c.size(); int randomStep = 0; Iterator<K> iter = c.iterator(); for (int i = 0; i < newSize; i++) { randomStep = (int) Math.floor(Math.random() * (s / newSize)) - 1; ... |
int | gaussianInt(Random random, int min, int max) gaussian Int if (max < min) { throw new IllegalArgumentException("max < min"); double det = (random.nextGaussian() + GAUSSIAN_LIMIT) / GAUSSIAN_LIMIT / 2.0d; return min + (int) (det * (max - min)); |
void | generateRandom(byte[] byteArray) Generates a number of random alpha-numeric characters in US-ASCII int i; randomGenerator.nextBytes(byteArray); for (i = 0; i < byteArray.length; i++) { if (byteArray[i] < 0) byteArray[i] *= -1; while (!((byteArray[i] >= 65 && byteArray[i] <= 90) || (byteArray[i] >= 97 && byteArray[i] <= 122) || (byteArray[i] <= 57 && byteArray[i] >= 48))) { if (byteArray[i] > 122) ... |
String | generateRandom(int length, int type) generate Random if (1 == type) { Random r = new Random(); int randNum = 0; while (randNum < 100000) { randNum = (int) r.nextInt(999999); return randNum + ""; String base = null; if (2 == type) { base = "abcdefghijklmnopqrstuvwxyz"; } else { base = "abcdefghijklmnopqrstuvwxyz0123456789"; Random random = new Random(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < length; i++) { int number = random.nextInt(base.length()); sb.append(base.charAt(number)); return sb.toString(); |
String | generateRandom(Integer bitNum) generate Random if (bitNum == null) { bitNum = 32; String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; Random random = new Random(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < bitNum; i++) { int number = random.nextInt(base.length()); ... |
String | generateRandomIntegerId() generate Random Integer Id Random random = new Random(); long abs = Math.abs(random.nextLong()); return String.valueOf(abs); |