List of usage examples for java.util Random Random
public Random()
From source file:Main.java
public static long nextLong(int lower, int upper) { Random ra = new Random(); int n = lower + ra.nextInt(upper - lower); long m = ra.nextLong(); return n + m; }
From source file:Main.java
public static char RandomCharFromStr(String str) { Random random = new Random(); int index = random.nextInt(str.length()); return str.charAt(index); }
From source file:Main.java
public static float nextFloat(int lower, int upper) { Random ra = new Random(); int n = lower + ra.nextInt(upper - lower); float m = ra.nextFloat(); return n + m; }
From source file:Main.java
public static int[] 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];// ww w. j a v a2s. co m ar[i] = a; } return ar; }
From source file:Main.java
public static double nextDouble(int lower, int upper) { Random ra = new Random(); int n = lower + ra.nextInt(upper - lower); double m = ra.nextDouble(); return n + m; }
From source file:Main.java
public static String getRandomUserId(int i) { Random random = new Random(); StringBuilder stringbuilder = new StringBuilder(i); int j = 0;//from w ww . ja v a 2 s. co m do { if (j >= i) return stringbuilder.toString(); stringbuilder.append((char) (48 + random.nextInt(10))); j++; } while (true); }
From source file:Main.java
public static int radrom(int max, int position) { Random random = new Random(); int randomNum = random.nextInt(max); if (position == randomNum) { randomNum = radrom(max, position); }//from w w w . ja v a 2s. c o m return randomNum; }
From source file:Main.java
public static int generateRandom(int min, int max) { Random random = new Random(); int randomInt = random.nextInt((max - min) + 1) + min; if (randomInt > max) { randomInt -= min;//from w w w.j a v a 2 s . co m } return randomInt; }
From source file:Main.java
public static int[] shuffle(int[] numbers) { for (int i = 0; i < numbers.length; i++) { int swap = new Random().nextInt(i + 1); int temp = numbers[swap]; numbers[swap] = numbers[i];/*w ww. jav a 2s .c om*/ numbers[i] = temp; } return numbers; }
From source file:Main.java
public static String RandomStrFromArray(String[] array) { Random random = new Random(); int index = random.nextInt(array.length); return array[index]; }