-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathRandomizer.java
More file actions
49 lines (35 loc) · 1020 Bytes
/
Randomizer.java
File metadata and controls
49 lines (35 loc) · 1020 Bytes
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
// This specific Java code was given by CodeHS, to help with the random number aspect of the program
import java.util.*;
public class Randomizer
{
public static Random theInstance = null;
public Randomizer(){
}
public static Random getInstance(){
if(theInstance == null){
theInstance = new Random();
}
return theInstance;
}
public static boolean nextBoolean(){
return Randomizer.getInstance().nextBoolean();
}
public static boolean nextBoolean(double probability){
return Randomizer.nextDouble() < probability;
}
public static int nextInt(){
return Randomizer.getInstance().nextInt();
}
public static int nextInt(int n){
return Randomizer.getInstance().nextInt(n);
}
public static int nextInt(int min, int max){
return min + Randomizer.nextInt(max - min + 1);
}
public static double nextDouble(){
return Randomizer.getInstance().nextDouble();
}
public static double nextDouble(double min, double max){
return min + (max - min) * Randomizer.nextDouble();
}
}