Reputation: 9
Hello I am reading the book about programming in java and I found one issue which I cannot understand. The question is like this:
Write a program DiscreteDistribution.java that takes a variable number of integer command-line arguments and prints the integer i with probability proportional to the ith command-line argument.
I have no clue what this i with probability proportinoal to the ith command-line argument. Can someone help me understand it? Thanks so much.
Upvotes: 0
Views: 226
Reputation: 1954
Your program should accept a list of integers as input parameter. E.g.
<program> 1 4 5 3 7
<program> 5 4 2 8 9 0 1
are all valid inputs. Let's call the parameters A. A[x] is the x-th parameter.
Then you should print one single number i with the following probability.
P(i) = A[i] / sum(A[x])
Take the first input as example.
P(0) = 1 / 20
P(1) = 4 / 20
P(2) = 5 / 20
P(3) = 3 / 20
P(4) = 7 / 20
Upvotes: 1