"So how do you prepare for this type of survival situation?"

Be constantly aware of your surroundings and always carry at least 1 spare magazine.