-
Notifications
You must be signed in to change notification settings - Fork 0
/
PuzzleJava.java
61 lines (54 loc) · 2.74 KB
/
PuzzleJava.java
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
import java.util.Random;
import java.util.Arrays;
import java.util.ArrayList;
public class PuzzleJava {
//Takes in a array list defined on TestPuzzle.java and a random number
//The loop iterates 10 times adding 10 random numbers between 0 and 20 to
//rollsArray
public ArrayList<Integer> getTenRolls(Random randMachine, ArrayList<Integer>rollsArray) {
for(int i = 1; i <= 10; i ++) {
rollsArray.add(randMachine.nextInt(20));
}
return rollsArray;
}
//Takes in random utility char alphabet is set to a charArray, some tool i found on Stack
//overflow and returns alphabet with a random index number displaying a character
public char getRandomLetter(Random randMachine) {
char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
return alphabet[randMachine.nextInt(25)];
}
//Takes in random utility and takes the same alphabet char array from the above method,
//The password variable and alphabet is passed through a loop which iterates 8 times,
//password is concat with the alphabet where the character is converted to string and
//randomly picks a letter via random method-- returns the 8 letter password
public String generatePassword(Random randMachine) {
char[] alphabet = "abcdefghijklmnopqrstuvwxyz".toCharArray();
String password = "";
for(int i = 1; i <= 8; i ++) {
password += Character.toString(alphabet[randMachine.nextInt(25)]);
}
return password;
}
//This method takes in random utility and a integer length for the array length
//defined on TestPuzzle.java. An ArrayList is defined an returned as passwordSet,
//which is passed into a loop which iterates the amound given by the length argument,
//and passwordSet adds a randomly generated string from generatePassword method which
//passes in random utility.
public ArrayList<String> getNewPasswordSet(Random randMachine, int length) {
ArrayList<String> passwordSet = new ArrayList<String>();
for(int i = 1; i <= length; i ++) {
passwordSet.add(generatePassword(randMachine));
}
return passwordSet;
}
//This method is still a work in progress to shuffle an array randomly
// public ArrayList<Object> shuffleArray(Random randMachine, ArrayList<Object>randomShuffle, int size) {
// Object temp = randomShuffle.get(randMachine.nextInt(size-1));
// Object other = randomShuffle.get(randMachine.nextInt(size-1));
// for(int i = 0; i <= size; i ++) {
// temp = randomShuffle.get(randMachine.nextInt(size-1));
// other = temp;
// }
// return other;
// }
}