Weighted random generation in Python