Generating Random Numbers
Figure 545. Using
static
double random()
for (int i = 0; i < 10; i++) {
System.out.println(Math.random());
}
0.4754286988826202 0.0060114391743414375 ... 0.9047785351372987 0.2516070321935864
try(final Scanner scanner = new Scanner(System.in)) {
System.out.print("Enter an integer seed:");
final long seed = scanner.nextLong();
Random generator = new Random(seed);
for (int i = 0; i < 10; i++) {
System.out.print(generator.nextBoolean() + " ");
}
}
Enter an integer seed:4237549835735 false true true true false false false true false true