Sampling algorithm