rejection sampling algorithm python