added rejection sampling algorithm