List of usage examples for java.util Random Random
public Random()
From source file:Main.java
public static void main(String[] args) { Stream.generate(new Random()::nextInt).limit(5).forEach(System.out::println); }
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 a va 2 s . c om*/ }
From source file:RandDemo.java
public static void main(String args[]) { Random r = new Random(); double val; double sum = 0; int bell[] = new int[10]; for (int i = 0; i < 100; i++) { val = r.nextGaussian(); sum += val; double t = -2; for (int x = 0; x < 10; x++, t += 0.5) if (val < t) { bell[x]++;//from w w w. j a v a2 s .co m break; } } System.out.println("Average of values: " + (sum / 100)); for (int i = 0; i < 10; i++) { for (int x = bell[i]; x > 0; x--) System.out.print("*"); System.out.println(); } }
From source file:Main.java
public static void main(String[] args) { Stream.generate(new Random()::nextDouble).limit(10).forEach(System.out::println); }
From source file:MainClass.java
public static void main(String args[]) { Random randomNumbers = new Random(); // random number generator int face; // stores each random integer generated for (int i = 1; i <= 20; i++) { // pick random integer from 1 to 6 face = 1 + randomNumbers.nextInt(6); System.out.printf("%d ", face); // if i is divisible by 5, start a new line of output if (i % 5 == 0) System.out.println(); }/* w w w.jav a2 s. c o m*/ }
From source file:Main.java
public static void main(String[] args) { Random num = new Random(); int num0, num1, num2, num3, num4, num5, num6, num7; num0 = num.nextInt(7) + 1;// www.jav a 2 s . co m num1 = num.nextInt(8); num2 = num.nextInt(8); num3 = num.nextInt(643) + 101; num4 = num.nextInt(10); num5 = num.nextInt(10); num6 = num.nextInt(10); num7 = num.nextInt(10); String randnum = "A random phone number: "; System.out.print(randnum); System.out.print(num0); System.out.print(num1); System.out.print(num2); System.out.print("-" + num3 + "-"); System.out.print(num4); System.out.print(num5); System.out.print(num6); System.out.println(num7); }
From source file:Main.java
public static void main(String[] args) throws Exception { int[] ints = new Random().ints(1, 50).distinct().limit(6).toArray(); System.out.println(Arrays.toString(ints)); }
From source file:Main.java
public static void main(String[] args) { Random randomGenerator = new Random(); BigInteger randomInteger = new BigInteger(1024, randomGenerator); System.out.println(randomInteger); }
From source file:Main.java
public static void main(String[] args) { Random rand = new Random(); int randnumb; int array[] = new int[5]; for (int j = 0; j <= 4; j++) { randnumb = 1 + rand.nextInt(11); array[j] = randnumb;//from w w w. j a v a 2 s . co m } System.out.println(Arrays.toString(array)); }
From source file:Main.java
public static void main(String args[]) { Random randomno = new Random(); // create byte array byte[] nbyte = new byte[30]; // put the next byte in the array randomno.nextBytes(nbyte);//ww w .j av a 2 s. c o m // check the value of array System.out.println("Value of byte array: " + Arrays.toString(nbyte)); }