List of usage examples for java.util Random nextInt
public int nextInt(int bound)
From source file:Main.java
public static void main(String[] argv) { Random r = new Random(); int randint = r.nextInt(10); System.out.println(randint);/*from w w w. j ava 2 s . co m*/ }
From source file:MainClass.java
public static void main(String[] args) { Random diceValues = new Random(); System.out.println(diceValues.nextInt(6)); System.out.println(diceValues.nextInt(6)); }
From source file:Main.java
public static void main(String[] args) { String[] arr = { "A", "B", "C", "D" }; Random random = new Random(); int select = random.nextInt(arr.length); System.out.println("Random String selected: " + arr[select]); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Random rand = new Random(); int n = 10;/*from ww w .j ava 2 s .com*/ int i = rand.nextInt(n + 1); System.out.println(i); }
From source file:Test.java
public static void main(String[] args) throws Exception { Lock myLock = new ReentrantLock(); Random random = new Random(); myLock.lock();//from w ww . ja v a2 s. co m 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) { Set<Integer> intSet = new LinkedHashSet<Integer>(); Random r = new Random(); while (intSet.size() <= 6) { intSet.add(r.nextInt(49)); }//from w w w.j a v a 2 s . c o m System.out.println(intSet); }
From source file:Main.java
public static void main(String[] args) { Random rand = new Random(); for (int i = 1; i <= 100; i++) { int randomNum = rand.nextInt((999 - 100) + 1) + 100; System.out.println(randomNum); }/*w w w. j a v a 2s . c o m*/ }
From source file:Main.java
public static void main(String[] args) { int[] anArray = new int[1000]; Random generator = new Random(); for (int i = 0; i < 1000; i++) { anArray[i] = (generator.nextInt(1000) + 1); }//from ww w .j a v a 2s . co m Date before = new Date(); Arrays.sort(anArray); Date after = new Date(); System.out.println("milli seconds" + (after.getTime() - before.getTime())); }
From source file:Main.java
public static void main(String args[]) { Random randomno = new Random(); // check next int value System.out.println("Next int value: " + randomno.nextInt(10000)); }
From source file:Main.java
public static void main(String... args) { Random rand = new Random(); int[] a = new int[100]; for (int i = 0; i < 100; i++) { a[i] = rand.nextInt(100); System.out.print(a[i] + ", "); if ((i + 1) % 10 == 0) { System.out.println(); }//www .j av a2s. c o m } }