List of usage examples for java.util Random Random
public Random()
From source file:Main.java
public static String getRandomTAG(List<String> list) { Random random = new Random(); int i = random.nextInt(list.size()); return list.get(i); }
From source file:Main.java
private static String randomMac() { String chars = "abcde0123456789"; String res = ""; Random rnd = new Random(); int leng = chars.length(); for (int i = 0; i < 17; i++) { if (i % 3 == 2) { res = res + ":"; } else {/* w ww. j a v a 2 s . com*/ res = res + chars.charAt(rnd.nextInt(leng)); } } return res; }
From source file:Main.java
private static String randomMac1() { String chars = "ABCDE0123456789"; String res = ""; Random rnd = new Random(); int leng = chars.length(); for (int i = 0; i < 17; i++) { if (i % 3 == 2) { res = res + ":"; } else {/*from w w w.j a v a2s . co m*/ res = res + chars.charAt(rnd.nextInt(leng)); } } return res; }
From source file:Main.java
public static String getRandomString(int len) { String returnStr = ""; char[] ch = new char[len]; Random rd = new Random(); for (int i = 0; i < len; i++) { ch[i] = (char) (rd.nextInt(9) + 97); }// w w w. j a va 2 s.c o m returnStr = new String(ch); return returnStr; }
From source file:Main.java
public static int randomColor() { Random random = new Random(); int r = random.nextInt(256); int g = random.nextInt(256); int b = random.nextInt(256); double color_perception = 1 - (0.299 * r + 0.587 * g + 0.114 * b) / 255; if (color_perception > 0.4) { return Color.argb(255, r, g, b); } else {//from www . ja v a 2 s .co m return randomColor(); } }
From source file:Main.java
public static int[] randomSort(int[] seed) { int len = seed.length; int[] result = new int[len]; Random random = new Random(); for (int i = 0; i < len; i++) { int r = random.nextInt(len - i); result[i] = seed[r];//w w w . ja v a 2 s . c om seed[r] = seed[len - 1 - i]; } return result; }
From source file:Main.java
static int randomOneOrMinusOne() { Random rand = new Random(); if (rand.nextBoolean()) return 1; else//from w ww .ja v a 2s . c o m return -1; }
From source file:Main.java
private static String randomSSID(int n) { String chars = "abcdeifABCDEIF0123456789"; String res = ""; Random rnd = new Random(); int leng = chars.length(); for (int i = 0; i < n; i++) { res = res + chars.charAt(rnd.nextInt(leng)); }//from w ww . j ava 2 s . co m return res; }
From source file:Main.java
public static int getRandomNumberByMaxNum(int maxNum) { if (maxNum == 0) { return getRandomNumber(); }//from w w w . j a v a 2 s.co m return new Random().nextInt(maxNum) + 1; }
From source file:Main.java
public static int generateRandomColor() { Random rnd = new Random(); int r = rnd.nextInt(256); int g = rnd.nextInt(256); int b = rnd.nextInt(256); if ((r == 0 && g == 0 && b == 0) || (r == 255 && g == 255 && b == 255)) { return generateRandomColor(); }/*ww w. j av a 2s .c om*/ int color = Color.argb(30, r, g, b); return color; }