List of usage examples for java.util Random Random
public Random()
From source file:Main.java
public static int generateState(int previous) { int generated = new Random().nextInt(4); return generated != previous ? generated : generateState(previous); }
From source file:Main.java
public static int randomInt(int min, int max) { Random random = new Random(); int randomInt = random.nextInt((max - min) + 1) + min; return randomInt; }
From source file:Main.java
public static String getRandomNum() { StringBuffer sb = new StringBuffer(); Random random = new Random(); for (int i = 0; i < 3; i++) { sb.append(random.nextInt(9));//from w w w .j a v a 2 s. co m } return sb.toString(); }
From source file:Main.java
public static int getRandomNumber(int start, int end) { end++;/*from w ww . ja v a 2s. com*/ Random random = new Random(); int result = -1; if (start == 0) { result = random.nextInt(end); } else { result = random.nextInt(end); if (result < start) { result = result + start; } } return result; }
From source file:Main.java
public static int handleRange(int i1, int i2) { Random rand = new Random(); int result;/*from ww w . j a va2 s . c om*/ int range; int loc; if (Double.valueOf(i1) > Double.valueOf(i2)) { range = (int) ((Double.valueOf(i1) * 100) - (Double.valueOf(i2) * 100)); loc = (int) (Double.valueOf(i2) * 100); } else { range = (int) ((Double.valueOf(i2) * 100) - (Double.valueOf(i1) * 100)); loc = (int) (Double.valueOf(i1) * 100); } result = (loc + rand.nextInt(range + 1)) / 100; return result; }
From source file:Main.java
public static int getRandom(int max, int min) { // TODO Auto-generated method stub Random random = new Random(); int getRandom = random.nextInt(max - min + 1) + min; return getRandom; }
From source file:Main.java
public static int getRnd() { if (random == null) { random = new Random(); }/*from w w w . j a v a 2 s.c o m*/ return random.nextInt(); }
From source file:Main.java
public static int getRandomNumber(int[] randomNumber) { int length = randomNumber.length; Random ran = new Random(); return randomNumber[ran.nextInt(length)]; }
From source file:Main.java
public synchronized static Long createId() { int max = 999; int min = 100; Random random = new Random(); Integer s = random.nextInt(max) % (max - min + 1) + min; Long currentTimeMillis = System.currentTimeMillis(); return Long.parseLong(currentTimeMillis.toString() + s.toString()); }
From source file:Main.java
public static String genRandomSeq(int length) { String val = ""; Random random = new Random(); for (int i = 0; i < length; i++) { // Determine character or digit String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num"; if ("char".equalsIgnoreCase(charOrNum)) { int choice = random.nextInt(2) % 2 == 0 ? 65 : 97; val += (char) (choice + random.nextInt(26)); } else if ("num".equalsIgnoreCase(charOrNum)) { val += String.valueOf(random.nextInt(10)); }//from w ww .j a va 2 s. c o m } return val; }