proto type python version of multinomial code - workarond overflows