-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuberQ.java
More file actions
41 lines (28 loc) · 694 Bytes
/
uberQ.java
File metadata and controls
41 lines (28 loc) · 694 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
import java.util.Random;
import java.util.HashMap;
public class uberQ {
public static void main(String[] args){
String [] elements = {"a", "b", "c"};
int [] weights = {10, 2, 3};
//loop 600 times
//count when is a, b, or c
//print times counted for each element
}
public static String choose(String[] elements, int[] weights){
Random r = new Random();
int base = 0;
int seed = 0;
for (int x : weights ) {
base += x;
}
seed = r.nextInt(base);
int temp = weights[0];
for (int i = 0; i < weights.length ; i++ ) {
if (seed <= temp) {
return elements[i];
}
temp += weights[i + 1];
}
return "not here";
}
}