List of utility methods to do Random Int
int | randomIntInRange(int lowerBound, int upperBound) random Int In Range if (upperBound < lowerBound) throw new IllegalArgumentException("lowerBound must be smaller than upperBound"); if (upperBound == lowerBound) return upperBound; double rand = Math.random(); rand = rand * (upperBound - lowerBound); rand += lowerBound; float r = (float) rand; ... |
int | randomIntRange(int low, int high) Get a random integer in the given half-open range. return low + ((int) Math.floor(Math.random() * (high - low))); |
int | randomIntWithDigits(int digits) random Int With Digits int max = (int) Math.pow(10, digits) + 1; return randomIntWithMinMax(0, max); |
String | randomKey(int sLen) random Key String base; String temp; int i; int p; base = "1234567890abcdefghijklmnopqrstuvwxyz"; temp = ""; for (i = 0; i < sLen; i++) { p = (int) (Math.random() * 37); ... |
int[][] | randomMatrix(int x, int y) random Matrix int[][] matrix = new int[x][y]; for (int i = 0; i < matrix.length; i++) { for (int j = 0; j < matrix[0].length; j++) { matrix[i][j] = (int) (Math.random() * 10); return matrix; |
String | randomModuleName(int count) Generate random module name. String upperCaseAlpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; String lowerCaseAlpha = "abcdefghijklmnopqrstuvwxyz"; String alpha = upperCaseAlpha + lowerCaseAlpha; StringBuilder builder = new StringBuilder(); while (count-- != 0) { int character = (int) (Math.random() * alpha.length()); builder.append(alpha.charAt(character)); return builder.toString(); |
int | randomNum(int n) random Num return (int) (Math.random() * Math.pow(10, n)); |
String | randomNum(int number) random Num StringBuffer result = new StringBuffer(); for (int i = 0; i < number; i++) { int random = (int) (Math.random() * 10); result.append(random); return result.toString(); |
int | randomNumber(int lower, int upper) random Number return lower + (int) (Math.random() * ((upper - lower) + 1)); |
int | randomNumber(int lower_bound, int higher_bound) Random number. int random_number = lower_bound + (int) (Math.random() * ((higher_bound - lower_bound) + 1)); return random_number; |