Functions to implement Generalized Direct Sampling