-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP1for2016.java
More file actions
41 lines (28 loc) · 832 Bytes
/
P1for2016.java
File metadata and controls
41 lines (28 loc) · 832 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
public class P1for2016 {
public static void main(String[] args){
String str[] = new String[]{"2","3","4"};
RandomStringChooser rsc = new RandomStringChooser(str);
}
}
class RandomStringChooser {
private String[] values;
private int valuesRemaining;
public RandomStringChooser(String[] str)
{
values = new String[str.length];
for(int i = 0; i < values.length; i++)
values[i] = str[i];
valuesRemaining = values.length;
}
public String getNext()
{
if(valuesRemaining == 0) {
return "NONE";
}
int index = (int) (Math.random() * valuesRemaining);
String selected = values[index];
values[index] = values[valuesRemaining - 1];
valuesRemaining--;
return selected;
}
}