List of usage examples for java.util Random nextInt
public int nextInt(int bound)
From source file:Main.java
public static String generateBoundary() { StringBuilder buffer = new StringBuilder(); Random rand = new Random(); int count = rand.nextInt(11) + 30; // a random size from 30 to 40 for (int i = 0; i < count; i++) { buffer.append(MULTIPART_CHARS[rand.nextInt(MULTIPART_CHARS.length)]); }/* w ww.j a v a2s .c om*/ return buffer.toString(); }
From source file:Main.java
public static int getRandom(int min, int max) { Random random = new Random(); int s = random.nextInt(max) % (max - min + 1) + min; return s;// ww w . j a v a2 s .c o m }
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 w w w .j a v a 2 s .c o m return randomColor(); } }
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(); }/* w w w . java 2 s . co m*/ int color = Color.argb(30, r, g, b); return color; }
From source file:Main.java
public static int randomColor() { Random rnd = new Random(); int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)); return color; }
From source file:Main.java
public static int generateColor() { Random random = new Random(); final float hue = random.nextInt(360); final float saturation = (random.nextInt(7000) + 2000) / 10000f; final float luminance = 0.3f; float[] hsv = { hue, saturation, luminance }; return Color.HSVToColor(hsv); }
From source file:Main.java
public static <T> T getRandomFrom(Set<T> set, Random random) { int randomIndex = random.nextInt(set.size()); Iterator<T> iterator = set.iterator(); for (int i = 0; i < randomIndex; i++) { if (!iterator.hasNext()) break; iterator.next();/*from ww w. jav a 2s. c o m*/ } return iterator.next(); }
From source file:Main.java
public static int GetRandomColor() { Random random = new Random(); int p = random.nextInt(Colors.length); while (Colors[p].equals(lastColor0) || Colors[p].equals(lastColor1) || Colors[p].equals(lastColor2)) { p = random.nextInt(Colors.length); }/*from ww w . j a va2 s. c o m*/ lastColor0 = lastColor1; lastColor1 = lastColor2; lastColor2 = Colors[p]; return Color.parseColor(Colors[p]); }
From source file:Main.java
static void shuffleArray(int[] ar) { Random rnd = new Random(); for (int i = ar.length - 1; i > 0; i--) { int index = rnd.nextInt(i + 1); // Simple swap int a = ar[index]; ar[index] = ar[i];/* w ww. jav a 2s . c o m*/ ar[i] = a; } }
From source file:Main.java
public static int getRandomColor() { Random rndcolor = new Random(); int color = Color.argb(255, rndcolor.nextInt(256), rndcolor.nextInt(256), rndcolor.nextInt(256)); return color; }