List of usage examples for java.util Random Random
public Random()
From source file:Main.java
/** * Generate the random byte to be sent// ww w.j a v a 2 s .com * * @return the random byte */ private static byte randomByte() { return (byte) (127 - new Random().nextInt(256)); }
From source file:Main.java
public static String getRandomStr(int len) { Random rd = new Random(); String retStr = ""; do {/*www. ja v a 2s. c om*/ int rdGet1 = Math.abs(rd.nextInt()) % 10; int rdGet2 = Math.abs(rd.nextInt()) % 26 + 65; retStr = retStr + rdGet1 + (char) rdGet2; } while (retStr.length() < len); return retStr; }
From source file:Main.java
public static List<Integer> randomChoose(int total, int selectedCount) { Random random = new Random(); List<Integer> resultList = new ArrayList<Integer>(); while (resultList.size() < selectedCount) { Integer randomNum = random.nextInt(total) + 1; if (!resultList.contains(randomNum)) { resultList.add(randomNum);//from w w w . j ava 2s.co m } } return resultList; }
From source file:Main.java
public synchronized static String getRandomCode(int length) { String sRand = ""; for (int i = 0; i < length; i++) { Random random = new Random(); String rand = String.valueOf(random.nextInt(10)); sRand += rand;//w w w .ja va 2s. com } return sRand; }
From source file:Main.java
public static String randomString(int length) { String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; Random random = new Random(); StringBuffer buf = new StringBuffer(); for (int i = 0; i < length; i++) { int num = random.nextInt(62); buf.append(str.charAt(num));/*from w w w. ja v a 2 s . com*/ } return buf.toString(); }
From source file:Main.java
public static GradientDrawable createBackgroundRandom() { Random rnd = new Random(); int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)); GradientDrawable gd = new GradientDrawable(); gd.setColor(color);/*from w w w . j a v a 2 s. c om*/ gd.setCornerRadius(5); gd.setAlpha(90); return gd; }
From source file:Main.java
public static int randomNumber(int num) { if (count++ > 8) { r = new Random(); }/*w ww. ja va2 s . c o m*/ return r.nextInt(num); }
From source file:Main.java
public static String get_Random_Color() { String[] arr = { "#f44336", "#ff4081", "#ff5722", "#ff9800", "#03a9f4", "#009688", "#388e3c" }; Random rand = new Random(); int max = 5;/*from w w w.j ava 2 s. c o m*/ int min = 0; int num = rand.nextInt((max - min) + 1 + min); return arr[num]; }
From source file:Main.java
public static String getRandomKey(int length) { String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; Random random = new Random(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < length; ++i) { int number = random.nextInt(str.length() - 1);//[0,62) sb.append(str.charAt(number));/* ww w .ja v a 2 s . c om*/ } return sb.toString(); }
From source file:Main.java
public static String getRandomString(int length) { String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; Random random = new Random(); StringBuffer sb = new StringBuffer(); for (int i = 0; i < length; i++) { int number = random.nextInt(62); sb.append(str.charAt(number));/*from w ww. j a v a 2s. co m*/ } return sb.toString(); }