List of usage examples for java.util Random Random
public Random()
From source file:Main.java
public static void main(String args[]) { Random randomno = new Random(); // get next next pseudorandom value int value = randomno.nextInt(); // check the value System.out.println("Value is: " + value); }
From source file:Main.java
public static void main(String args[]) { Random randomno = new Random(); // get next next boolean value boolean value = randomno.nextBoolean(); // check the value System.out.println("Value is: " + value); }
From source file:Main.java
public static void main(String args[]) { Random randomno = new Random(); // setting seed randomno.setSeed(20);/*from w ww .j a v a2 s. c o m*/ // value after setting seed System.out.println("Object after seed: " + randomno.nextInt()); }
From source file:Main.java
public static void main(String args[]) { Random randomno = new Random(); // get next long value long value = randomno.nextLong(); // check the value System.out.println("Long value is: " + value); }
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);//from w w w . j ava 2 s . co m System.out.print(a[i] + ", "); if ((i + 1) % 10 == 0) { System.out.println(); } } }
From source file:Main.java
public static void main(String[] argv) throws Exception { Random rand = new Random(); long seed = rand.nextLong(); rand = new Random(seed); Random rand2 = new Random(seed); }
From source file:Main.java
public static final void main(String... args) { Random randomGenerator = new Random(); for (int idx = 1; idx <= 10; ++idx) { boolean randomBool = randomGenerator.nextBoolean(); System.out.println("Generated : " + randomBool); }//from w ww. ja v a 2 s .c o m }
From source file:Main.java
public static void main(String[] argv) throws Exception { Random rand = new Random(); byte[] bytes = new byte[5]; rand.nextBytes(bytes);// ww w . j a v a 2 s. com }
From source file:Main.java
public static void main(String[] argv) throws Exception { Random rand = new Random(); int n = 10;//w w w . j a v a2 s . c o m int i = rand.nextInt(n + 1); System.out.println(i); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Random rand = new Random(); boolean b = rand.nextBoolean(); long l = rand.nextLong(); float f = rand.nextFloat(); // 0.0 <= f < 1.0 double d = rand.nextDouble(); // 0.0 <= d < 1.0 }