-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathReplicatedRandomTest.java
More file actions
67 lines (60 loc) · 2.29 KB
/
ReplicatedRandomTest.java
File metadata and controls
67 lines (60 loc) · 2.29 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import java.util.Random;
public class ReplicatedRandomTest {
public static void main(String args[]) {
ReplicatedRandom rr = new ReplicatedRandom();
if (args.length == 1) {
// Assuming the argument is a string representing a double,
// replicate the Random that the double was generated from
if (rr.replicateState(Double.parseDouble(args[0]))) {
for (int j = 0; j < 10; j++)
System.out.println(rr.nextDouble());
}
return;
}
System.out.println("Replicating from Math.random");
for (int i = 0; i < 3; i++) {
if (rr.replicateState(Math.random())) {
for (int j = 0; j < 3; j++)
System.out.println(rr.nextDouble() + "\t" + Math.random());
System.out.println();
}
}
System.out.println("Replicating from nextDouble");
for (int i = 0; i < 3; i++) {
Random r = new Random(i);
if (rr.replicateState(r.nextDouble())) {
for (int j = 0; j < 3; j++)
System.out.println(rr.nextDouble() + "\t" + r.nextDouble());
System.out.println();
}
}
System.out.println("Replicating from nextInt");
for (int i = 0; i < 3; i++) {
Random r = new Random();
if (rr.replicateState(r.nextInt(), r.nextInt())) {
for (int j = 0; j < 3; j++)
System.out.println(rr.nextInt() + "\t" + r.nextInt());
System.out.println();
}
}
System.out.println("Replicating from nextLong");
for (int i = 0; i < 3; i++) {
Random r = new Random();
if (rr.replicateState(r.nextLong())) {
for (int j = 0; j < 3; j++)
System.out.println(rr.nextLong() + "\t" + r.nextLong());
System.out.println();
}
}
/*
for (int i = 0; i < 3; i++) {
Random r = new Random();
if (rr.replicateState(r.nextFloat(), r.nextFloat())) {
for (int j = 0; j < 3; j++)
System.out.println(rr.nextFloat() + "\t" + r.nextFloat());
System.out.println();
}
}
*/
}
}