if proposal < mode:
    acceptance_prob = (proposal - low) / (mode - low)
else:
    acceptance_prob = (high - proposal) / (high - mode)
if random() < acceptance_prob:
    break
return proposal
Python, SimPy: How to generate a value from a triangular probability distribution?