-
Notifications
You must be signed in to change notification settings - Fork 616
/
Copy pathRandomClass.java
45 lines (38 loc) · 1.25 KB
/
RandomClass.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// Java program to demonstrate
// method calls of Random class
import java.util.Random;
public class Test
{
public static void main(String[] args)
{
Random random = new Random();
System.out.println(random.nextInt(10));
System.out.println(random.nextBoolean());
System.out.println(random.nextDouble());
System.out.println(random.nextFloat());
System.out.println(random.nextGaussian());
byte[] bytes = new byte[10];
random.nextBytes(bytes);
System.out.printf("[");
for(int i = 0; i< bytes.length; i++)
{
System.out.printf("%d ", bytes[i]);
}
System.out.printf("]\n");
System.out.println(random.nextLong());
System.out.println(random.nextInt());
long seed = 95;
random.setSeed(seed);
// Note: Running any of the code lines below
// will keep the program running as each of the
// methods below produce an unlimited random
// values of the corresponding type
/* System.out.println("Sum of all the elements in the IntStream returned = " +
random.ints().count());
System.out.println("Count of all the elements in the DoubleStream returned = " +
random.doubles().count());
System.out.println("Count of all the elements in the LongStream returned = " +
random.longs().count());
*/
}
}