Given
$R=\{r_1,...,r_n\}$ where n is finite and all r are positive integers
positive integer b
How can I find a probability function $P=\{p_1,...,p_n\}$ such that :
- $sum(P*R)=b$ ([expected value][1] equals b)
- $sum(Plog(1/P))$ is maximized ([entropy][2] is maximized)
Use Lagrange multipliers, via $$J(p_1,\ldots,p_n)=-\sum_{i=1}^n p_i \log p_i +\lambda(\sum_{i=1}^n r_i p_i - b).$$
It yields that the optimal distribution is of the form $$ p_k= \frac{e^{\lambda r_k}}{\sum_{i=1}^n e^{\lambda r_i}} $$ In general, this has to be solved numerically, to ensure it satisfies the constraint on expectation. The normalisation is taken care of by the division. Of course, the integer constraints mean that a solution may not exist under some conditions.
Edit: As I said a solution may not exist. For example, forgetting the normalization and the expectation for now, let $(r_1,r_2,r_3)=(1,3,4).$ This will give $p_1=e^{\lambda},p_2=e^{3\lambda},$ and $p_3=e^{4\lambda}.$ For simplicity put $x=e^{\lambda}.$ Then you are required to have $$ \frac{x+3x^3+4x^4}{x+x^3+x^4}=b, $$ (the numerator now comes in to make the probabilities add up to one). Simplifying we have $$ x((b-1)+(b-3)x^2+(b-4)x^3)=0, $$ but this polynomial may not have a positive real solution (required since $x=e^{\lambda}$) for the given $b.$
Actually, I was stupid. Note that for a well-posed problem the expectation $b$ has to be (clearly!) in the interval $[1,4]$ (and in general in the interval from the minimum to the maximum of the $r_i$). The boundary cases have a trivial distribution supported only on one point. Otherwise, let $b\in (1,4)$ and note that by continuity there will be a solution in positive $x$ to the equation.