If I have $N$ fixed positive integer and $N$   i.i.d rv´s. $X_1,X-2,...,X_N$, and parameters $a_i$ such that $\displaystyle\sum_{i=1}^N{a_i}=1$, it is well known that there is a global maximum of

$f(a_1,a_2,...,a_N)=Eu(\displaystyle\sum_{i=1}^N{u(a_iX_i)}$ when $a_i=1/n$, for a concave function $u$.

How do I find the maximum if $N$ instead of being fixed is a discrete random variable that takes positive integers.