proto type python version of multinomial code