Drawing a random number from a discrete distribution function stored as a sequence of probabilities in F#
问题 There is a given sequence of floats (between 0 and 1) of finite length N which denotes a distribution function over integers 0..N-1. We are trying to draw a random number from this distribution. One way of doing it is to draw a uniform random variable in [0, 1] (float), and then calculate the inverse cumulative distribution function for that number. If the distribution was in an array, the code would look something like this: let matched distribution draw = let rec matchRest distribution draw