List of usage examples for java.lang Math random
public static double random()
From source file:Main.java
public static void main(String[] argv) throws Exception { String[] items = new String[50]; for (int i = 0; i < items.length; i++) { items[i] = "" + Math.random(); }//from w w w .j av a2 s .com JComboBox cb = new JComboBox(items); // Retrieve the current max visible rows int maxVisibleRows = cb.getMaximumRowCount(); // Change the current max visible rows maxVisibleRows = 20; cb.setMaximumRowCount(maxVisibleRows); }
From source file:MainClass.java
public static void main(String[] arg) { long[][][] beans = new long[5][10][30]; for (int i = 0; i < beans.length; i++) { for (int j = 0; j < beans[i].length; j++) { beans[i][j] = new long[(int) (1.0 + 6.0 * Math.random())]; }/*from w ww .ja va2 s.com*/ } }
From source file:Main.java
public static void main(String args[]) { double limits[] = { 0.0, 0.1, 0.3, 0.7 }; String labels[] = { "very low", "low", "moderate", "high" }; ChoiceFormat format = new ChoiceFormat(limits, labels); double r = Math.random(); System.out.println(format.format(r) + " (" + r + ")."); }
From source file:Random1.java
public static void main(String[] argv) { //+/* ww w . j a v a 2s .c om*/ // java.lang.Math.random() is static, don't need to construct Math System.out.println("A random from java.lang.Math is " + Math.random()); //- }
From source file:MessageFormatApp.java
public static void main(String args[]) { String pattern = "The time is {0,time} and "; pattern += "your lucky number is {1,number}."; MessageFormat format = new MessageFormat(pattern); Object objects[] = { new Date(), new Integer((int) (Math.random() * 1000)) }; String formattedOutput = format.format(objects); System.out.println(formattedOutput); }
From source file:Main.java
public static void main(String[] args) { ForkJoinPool fjPool = new ForkJoinPool(); int[] a = new int[3333344]; for (int i = 0; i < a.length; i++) { int k = (int) (Math.random() * 22222); a[i] = k;//from www .ja v a 2 s .com } ForkJoinQuicksortTask forkJoinQuicksortTask = new ForkJoinQuicksortTask(a, 0, a.length - 1); long start = System.nanoTime(); fjPool.invoke(forkJoinQuicksortTask); System.out.println("Time: " + (System.nanoTime() - start)); }
From source file:Main.java
public static void main(String[] args) { List<Integer> list = new ArrayList<>(); long expectedSum = 0; for (int i = 0; i < 10000; i++) { int random = 1 + (int) (Math.random() * ((100 - 1) + 1)); list.add(random);//from w ww. jav a 2 s . co m expectedSum += random; } System.out.println("expected sum: " + expectedSum); ForkJoinPool forkJoinPool = new ForkJoinPool(Runtime.getRuntime().availableProcessors()); RecursiveSum recursiveSum = new RecursiveSum(list, 0, list.size()); long recSum = forkJoinPool.invoke(recursiveSum); System.out.println("recursive-sum: " + recSum); }
From source file:ItemSet.java
public static void main(String args[]) { String names[] = { "Item 1", "Item 2", "Item 3" }; Set moons = new HashSet(); int namesLen = names.length; int index;/*from ww w .j av a2 s . com*/ for (int i = 0; i < 100; i++) { index = (int) (Math.random() * namesLen); moons.add(names[index]); } Iterator it = moons.iterator(); while (it.hasNext()) { System.out.println(it.next()); } System.out.println("---"); Set orderedMoons = new TreeSet(moons); it = orderedMoons.iterator(); while (it.hasNext()) { System.out.println(it.next()); } }
From source file:Main.java
public static void main(String[] args) { ArrayList<String> list = new ArrayList<>(); list.add("A"); list.add("B"); list.add("C"); list.add("D"); list.add("E"); list.add("F"); list.add("G"); list.add("H"); System.out.println(list);/* w ww . j a v a 2 s.co m*/ while (!list.isEmpty()) { long index = Math.round(Math.floor(Math.random() * list.size())); System.out.println("Name " + list.get((int) index)); list.remove((int) index); } }
From source file:RandomBounds.java
public static void main(String[] args) { if (args.length != 1) usage();//from www.j a v a 2 s . c o m if (args[0].equals("lower")) { while (Math.random() != 0.0) ; // Keep trying System.out.println("Produced 0.0!"); } else if (args[0].equals("upper")) { while (Math.random() != 1.0) ; // Keep trying System.out.println("Produced 1.0!"); } else usage(); }