List of usage examples for java.util Random Random
public Random()
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 getRandomNumber() { return new Random().nextInt(100) + 1; }
From source file:Main.java
public static int randomColor() { // http://developer.android.com/reference/android/graphics/Color.html#HSVToColor%28float%5B%5D%29 float hue = new Random().nextInt(360); // 0 - 360 float saturation = randomInRange(0.5f, 0.8f); // 0.5 to 0.8, away from white. but not too intense float brightness = randomInRange(0.5f, 0.8f); // 0.5 to 0.8, away from black, but not too light return Color.HSVToColor(new float[] { hue, saturation, brightness }); }
From source file:Main.java
/** * Shuffle an array./* w w w . j a v a2 s. co m*/ * @param array Array. */ private static void Shuffle(double[] array) { Random random = new Random(); for (int i = array.length - 1; i > 0; i--) { int index = random.nextInt(i + 1); double temp = array[index]; array[index] = array[i]; array[i] = temp; } }
From source file:Main.java
/** * Generate array of alphabet//from www . j av a 2 s . co m * @return String */ public static String generateAlphabet(int length) { String alphabet = "abcdefghijklmnopqrstuvwxyz"; String randomAlphabet = ""; Random random = new Random(); for (int i = 0; i < length; i++) { randomAlphabet = randomAlphabet + alphabet.charAt(random.nextInt(alphabet.length())); } return randomAlphabet; }
From source file:Main.java
/** * Generate array of Number//from w ww . j a v a 2 s . c o m * @param length int * @return String */ public static String generateNumber(int length) { String numbers = "0123456789"; String randomNumber = ""; Random random = new Random(); for (int i = 0; i < length; i++) { randomNumber = randomNumber + numbers.charAt(random.nextInt(numbers.length())); } return randomNumber; }
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 av a2 s . c o m } set.add(i); a[x] = i; } return a; }
From source file:Main.java
public static char randomChar(String alphabet) { return alphabet.charAt(new Random().nextInt(alphabet.length())); }
From source file:Main.java
public static <T> List<T> getRandomCollection(Class<T> collectionType) { int collectionSize = new Random().nextInt(10); List<T> collection = new ArrayList<T>(); for (int i = 0; i < collectionSize; i++) { Object obj = getRandomValue(collectionType); if (obj != null && obj.getClass().isAssignableFrom(collectionType)) { collection.add((T) obj);/*from ww w . j a va 2s . com*/ } } return collection; }
From source file:Main.java
/** * Get a random number between a min and max * @param min lower end min/* w ww .ja va 2 s .c o m*/ * @param max higher end max * @return */ public static int getRandomInt(int min, int max) { Random rand = new Random(); int randomNum = rand.nextInt((max - min) + 1) + min; return randomNum; }