uses initial probabilities, refactored code for random value