Added code for sampling from a discrete distribution.