List of utility methods to do Random Number
String | getNumberedUsername(String fn, String ln) get Numbered Username Random r = new Random(); return fn + ln + r.nextInt(100); |
int | getNumberInRange(int minimum, int maximum) Produces a number within the specified range. return new Random().nextInt(maximum - minimum + 1) + minimum; |
long | getNumberLong() get Number Long return Math.abs(ran.nextLong());
|
String | getNumbers() get Numbers Random random = new Random(); String result = random.nextInt(1000000) + ""; if (result.length() != length) { return getNumbers(); return result; |
String | getNumbersAndAlphabet() get Numbers And Alphabet Random random = new Random(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < length; i++) { sb.append(getRandomString(random.nextInt(randString.length()))); return sb.toString(); |
String | getNumString(int length) get Num String StringBuffer sb = new StringBuffer(); for (int i = 0; i < length; i++) { sb.append(NUMBERCHAR.charAt(random.nextInt(NUMBERCHAR.length()))); return sb.toString(); |
String | getPhoneNumber() get Phone Number return "0011" + getRandomNumber(9) + getRandomNumber(9) + getRandomNumber(9) + getRandomNumber(9) + getRandomNumber(9) + getRandomNumber(9) + getRandomNumber(9) + getRandomNumber(9) + getRandomNumber(9) + getRandomNumber(9); |
int | getPositiveNumber(int maximum) Gets a random positive number with specified length. return RANDOM.nextInt(maximum) + 1;
|
String | getRandNum(int charCount) get Rand Num String charValue = ""; for (int i = 0; i < charCount; i++) { char c = (char) (randomInt(0, 10) + '0'); charValue += String.valueOf(c); return charValue; |
String | getRandNum(int num) get Rand Num String res = ""; if (num < 1) return res; String arr[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9" }; for (int i = 0; i < num; i++) { Random ran = new Random(); int index = ran.nextInt(10); res = res + arr[index]; ... |