-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtilities.java
More file actions
56 lines (46 loc) · 1.54 KB
/
Copy pathUtilities.java
File metadata and controls
56 lines (46 loc) · 1.54 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
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
abstract class Utilities {
private static final Random rand = new Random();
public static final boolean isDebugging = true;
public static final String ATMName = "Brand New ATM";
// the denominations that the vault can hold
public static final List<Integer> stdDenominations =
new ArrayList<>(Arrays.asList(50, 20, 10, 5));
/**
* Generates a random credit card number
*
* @return A random credit card number
*/
static public String genRandCCNumber() {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 16; i++) {
sb.append(randNumber(0, 9));
}
return sb.toString();
}
/**
* Generates a random number
*
* @param min The smallest number to generate
* @param max The maximum number to generate
* @return A random number between min and max, inclusive
*/
static public int randNumber(int min, int max) {
return rand.nextInt(max) + min;
}
/**
* Returns true based the desired probability
*
* @param prob The probability to return true
* @return True on the desired probability amount
*/
static public boolean randProbability(double prob) {
// http://stackoverflow.com/questions/11701399/
// round to three decimal places; multiply to remove decimal
double percentProb = (double) Math.round(prob * 1000) / 10;
return Utilities.randNumber(0, 100) <= Math.round(percentProb);
}
}