I am not sure about the method (area under the curve of the pdf should be equal 1, and what about its value in your case?), but you can increase speed of computations, if you avoid Python loops. In your case, you can do it as follows:
import numpy as np # --- Instead of while loop: # start = ... time measurement started .... u1 = np.random.uniform(a, b, size=100000) u2 = np.random.uniform(0, m, size=100000) var_inds = u2 <= f(u1) variables = u1[var_inds] rejected = (~var_inds).sum() #end = ... time measurement ended # some plotting stuff...