List of usage examples for java.util Random nextInt
public int nextInt(int bound)
From source file:Main.java
/** * Get a random number within a given upper limit; *///from w w w . j ava2 s .c o m public static int getRandomInt(int max) throws Exception { int ret; Random r = new Random(); ret = r.nextInt(max); Log.i(TAG, String.format("Generate an integer value: %d", ret)); return ret; }
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);// www. j a v a2 s. c o m gd.setCornerRadius(5); gd.setAlpha(90); return gd; }
From source file:Main.java
public static int[] sortearCores() { Random r = new Random(); return new int[] { coresSecretas[r.nextInt(7)], coresSecretas[r.nextInt(7)], coresSecretas[r.nextInt(7)] }; }
From source file:Main.java
public static int getRandomColor() { Random rand = new Random(); return Color.argb(100, rand.nextInt(256), rand.nextInt(256), rand.nextInt(256)); }
From source file:Main.java
public static String getRandomRGB() { String r, g, b;// w ww.j a v a 2 s . c o m Random random = new Random(); r = Integer.toHexString(random.nextInt(256)).toUpperCase(); g = Integer.toHexString(random.nextInt(256)).toUpperCase(); b = Integer.toHexString(random.nextInt(256)).toUpperCase(); r = r.length() == 1 ? "0" + r : r; g = g.length() == 1 ? "0" + g : g; b = b.length() == 1 ? "0" + b : b; return "#" + (r + g + b); }
From source file:Main.java
public static String getRandColorCode() { String r, g, b;/*from w ww .j a v a 2 s .c o m*/ Random random = new Random(); r = Integer.toHexString(random.nextInt(256)).toUpperCase(); g = Integer.toHexString(random.nextInt(256)).toUpperCase(); b = Integer.toHexString(random.nextInt(256)).toUpperCase(); r = r.length() == 1 ? "0" + r : r; g = g.length() == 1 ? "0" + g : g; b = b.length() == 1 ? "0" + b : b; return r + g + b; }
From source file:Main.java
public static Integer[] randomIntArray(int size) { Integer a[] = new Integer[size]; HashSet<Integer> set = new HashSet<>(); for (int x = 0; x < a.length; x++) { Random r = new Random(); Integer i = r.nextInt(size * 10); while (set.contains(i)) { i = r.nextInt(size);/*from w ww .j ava 2s. co m*/ } set.add(i); a[x] = i; } return a; }
From source file:Main.java
public static int randomRGB() { String r, g, b;// w w w. j a va 2 s . c o m Random random = new Random(); r = Integer.toHexString(random.nextInt(256)).toUpperCase(); g = Integer.toHexString(random.nextInt(256)).toUpperCase(); b = Integer.toHexString(random.nextInt(256)).toUpperCase(); r = r.length() == 1 ? "0" + r : r; g = g.length() == 1 ? "0" + g : g; b = b.length() == 1 ? "0" + b : b; return Color.parseColor("#" + (r + g + b)); }
From source file:Main.java
/** * Create a random string hex color.//w w w .j a v a 2 s . c o m * @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:com.dianping.dpsf.other.echo.SimpleEchoClient.java
private static List<String[]> generateHostList() { List<String[]> hostList = new ArrayList<String[]>(); hostList.add(new String[] { "127.0.0.1", "20001" }); hostList.add(new String[] { "127.0.0.1", "20002" }); hostList.add(new String[] { "127.0.0.1", "20003" }); Random rnd = new Random(System.currentTimeMillis()); int num = rnd.nextInt(3) + 1; Collections.shuffle(hostList); return hostList.subList(0, num); }