List of usage examples for java.util Random Random
public Random()
From source file:MainClass.java
public static void main(String[] args) { Random generator = new Random(); for (int i = 0; i < 10; i++) data[i] = 10 + generator.nextInt(90); Arrays.sort(data);/*from w w w .j a va 2 s . c o m*/ System.out.println(binarySearch(3)); }
From source file:MainClass.java
public static void main(String args[]) { Random generator = new Random(); for (int i = 0; i < 10; i++) System.out.println(generator.nextInt()); }
From source file:Main.java
public static void main(String[] args) { int[] a = new int[10]; int min = Integer.MAX_VALUE; int max = Integer.MIN_VALUE; for (int b = 0; b < a.length; b++) { a[b] = new Random().nextInt(100); }//from ww w .j a v a 2s . c o m for (int b = 0; b < a.length; b++) { if (a[b] < min) min = a[b]; if (a[b] > max) max = a[b]; } System.out.println("Min is: " + min + " " + "Max is: " + max); }
From source file:Main.java
public static void main(String[] args) { int[] nums = new int[100]; for (int i = 0; i < nums.length; ++i) { nums[i] = i + 1;/*w w w .j av a2s . c o m*/ } Random generator = new Random(); for (int i = 0; i < nums.length; ++i) { int arrayIndex = generator.nextInt(nums.length - i); int tmp = nums[nums.length - 1 - i]; nums[nums.length - 1 - i] = nums[arrayIndex]; nums[arrayIndex] = tmp; } System.out.println(Arrays.toString(nums)); }
From source file:Random2.java
public static void main(String[] argv) { //+/*from ww w . j a v a 2 s .c o m*/ // java.util.Random methods are non-static, so need to construct Random r = new Random(); for (int i = 0; i < 10; i++) System.out.println("A double from java.util.Random is " + r.nextDouble()); for (int i = 0; i < 10; i++) System.out.println("An integer from java.util.Random is " + r.nextInt()); //- }
From source file:Random3.java
public static void main(String[] argv) { // java.util.Random methods are non-static, do need to construct Math //+// www . j ava 2 s. co m Random r = new Random(); for (int i = 0; i < 10; i++) System.out.println("A gaussian random double is " + r.nextGaussian()); //- }
From source file:Test.java
public static void main(String[] args) throws Exception { Lock myLock = new ReentrantLock(); Random random = new Random(); myLock.lock();/* w w w. j av a2 s . com*/ int number = random.nextInt(5); int result = 100 / number; System.out.println("A result is " + result); FileOutputStream file = new FileOutputStream("file.out"); file.write(result); file.close(); }
From source file:Main.java
public static void main(String[] args) { String[] peoples = { "A", "B", "C", "D", "E", "F" }; List<String> names = Arrays.asList(peoples); for (int i = 0; i < peoples.length; i++) { int index = new Random().nextInt(names.size()); String anynames = names.get(index); System.out.println(anynames); }//from ww w. j a va 2s . co m }
From source file:MainClass.java
public static void main(String args[]) { Random generator = new Random(); for (int i = 0; i < 10; i++) { System.out.println(generator.nextGaussian()); }/*from ww w . j av a 2 s. c o m*/ }
From source file:Random4.java
public static void main(String[] argv) throws IOException { // java.util.Random methods are non-static, do need to construct Math Random r = new Random(); PrintWriter file1 = new PrintWriter(new FileWriter("file1")); PrintWriter file2 = new PrintWriter(new FileWriter("file2")); for (int i = 0; i < 10000; i++) { file1.println(r.nextDouble());//from ww w . j a v a 2 s . c o m file2.println(r.nextGaussian()); } file1.close(); file2.close(); }