Avoid port conflict when having multiple ports open in each container

I have an app that needs to run on 16 different ports. I plan to have several containers containing one or more apps like that in each. The point here is avoiding conflicts when mapping ports from containers to the local host machine (used port problem). I need a way that is programmable and automatic. Can I get done with kubernetes-python and how?