A linear-time algorithm for computing the multinomial stochastic