Implementing inverse cdf (quantile function)