added routines for sampling from discrete distributions.