I understand the question title is vague. My apologies. I have a hashmap that has the key:value <string>:<list of lists>. For a given list, each of the items in the list has a corresponding probability of being chosen. For example, one item in the hashmap might look like
"NP":[['A', 'B'], ['C', 'D', 'E'], ['F']]
I need to choose one of the lists on the right hand side randomly. Each list has it's own probability. Here are the input strings that would generate the above item in the map.
3 NP A B
1 NP C D E
1 NP F
Because the line NP A B has the number 3 next to it, NP C D E has 1 next to it, and NP F has 1 next to it, the probability ratio is 3:1:1, so [A, B] has 3/5 probability of being chosen, [C, D, E] has 1/5 of being chosen and same for [F.
My question is, how do I simulate those probabilities?
Before those numbers were introduced it was easy because I could count the length of the list (in the above example it would be 3) and then choose a random number between 0 and len(list) - 1 inclusive with random.randint(), then choose that index from the list. To simulate bernoulli random variables, I know that one can check if random.randint() < p. But that only works if you have 2 cases. I can't explicitly write if statements to check because a list might have n elements.