implemented multinomial sampling