The 18-year-old gunman who killed nine people in a shooting spree in Munich had been planning his crime for a year but chose his victims at random, officials said on Sunday.