Arduino keeps switching to wrong port

I am using linuxmint 17.3 Rosa. Every time I run some code, the arduino randomly switches from dev/ttyACM0 to dev/ttyACM1. It's impossible to use the software. How do you solve this?