rejection sampling algorithm