-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomizer.java
More file actions
46 lines (40 loc) · 1.24 KB
/
Randomizer.java
File metadata and controls
46 lines (40 loc) · 1.24 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
import java.util.Random;
/**
* Provide control over the randomization of the simulation. By using the
* shared, fixed-seed randomizer, repeated runs will perform exactly the same
* (which helps with testing). Set 'useShared' to false to get different random
* behaviour every time.
*
* @author Rayan Popat (K21056367) & James Coward (K22004743)
* @version 2023.02.23
*/
public class Randomizer {
// The default seed for control of randomization.
private static final int SEED = 1111;
// A shared Random object, if required.
private static final Random rand = new Random(SEED);
// Determine whether a shared random generator is to be provided.
private static final boolean useShared = true;
/**
* Provide a random generator.
*
* @return A random object.
*/
public static Random getRandom() {
if (useShared) {
return rand;
} else {
return new Random();
}
}
/**
* Reset the randomization.
* This will have no effect if randomization is not through
* a shared Random generator.
*/
public static void reset() {
if (useShared) {
rand.setSeed(SEED);
}
}
}