List of usage examples for java.util Random Random
public Random()
From source file:Main.java
public static String getRandomFileName() { String _df = android.text.format.DateFormat.format("MMddyyyyhhmmss", new java.util.Date()).toString(); Random r = new Random(); int random = Math.abs(r.nextInt() % 100); return String.format("%d%s.jpg", random, _df); }
From source file:Main.java
public static String getRandom(int len, String[] arr) { String s = ""; if (0 < len && null != arr && arr.length >= 0) { Random ra = new Random(); int arrLen = arr.length; for (int i = 0; i < len; i++) { s += arr[ra.nextInt(arrLen)]; }//ww w. ja va 2 s . co m return s; } else { return s; } }
From source file:Main.java
public static int[] getRandomArray(int length, int max) { int[] randArray = new int[length]; Random rand = new Random(); for (int i = 0; i < length; i++) { randArray[i] = rand.nextInt(max); }/*from ww w .j a v a 2s. c o m*/ Arrays.sort(randArray); for (int i = 1; i < length; i++) { if (randArray[i] == randArray[i - 1]) { randArray[i] += 1; } } for (int i = length - 1; i > 0; i--) { if (randArray[i] == randArray[i - 1]) { randArray[i - 1] -= 1; } } return randArray; }
From source file:Main.java
public static int genRand(int min, int max) { return (new Random()).nextInt(max) % (max - min + 1) + min; }
From source file:Main.java
private static String generateRandomCharacter() { final String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; final int length = alphabet.length(); Random random = new Random(); String randomChar = String.valueOf(alphabet.charAt(random.nextInt(length))); return randomChar; }
From source file:Main.java
public static List<String> generateWidth() { List<String> ids = new ArrayList<String>(); Random mRandom = new Random(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < 50; i++) { sb.delete(0, sb.length());/*w w w.j a va 2 s.co m*/ int height = mRandom.nextInt(250) + 100; sb.append(height); ids.add(sb.toString()); } return ids; }
From source file:Main.java
/** * Initialize the random number generator */ public static void randInit() { _rand = new Random(); }
From source file:Main.java
public static int[] randNum(int num, int min, int max) { ArrayList<Integer> list = new ArrayList<Integer>(); Random rand = new Random(); while (true) { int rm = (rand.nextInt(max - min) + min); if (!list.contains(rm)) { list.add(rm);//from w w w . j ava 2 s . c o m if (list.size() >= num) break; } } int result[] = new int[num]; for (int i = 0; i < list.size(); i++) { result[i] = list.get(i); } return result; }
From source file:Main.java
/** * Create a random string hex color.//from w w w .j ava2 s . c om * @return string hex color */ public static String randomHex() { Random rnd = new Random(); return String.format("#%02X%02X%02X", rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)); }
From source file:Main.java
public static String generateRandomString(final int len) { final String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; final Random random = new Random(); final StringBuffer sb = new StringBuffer(); for (int i = 0; i < len; i++) { final int number = random.nextInt(base.length()); sb.append(base.charAt(number));//from ww w. ja v a 2 s .c o m } return sb.toString(); }