Optimized rejection sampling