
Psychology. Depending upon the motivation of a shooter, they will choose victims based on one of three things - supposed injury, dramatic impact or maximum chaos.
Supposed Injury is when the shooter choose their targets because the victims - in some fashion - emotionally, financially or in some other way injured or adversely affected the shooter. This can be direct as in the case of the neighbor offending the shooter or indirect as in a public figure or group that the target despises or feels is responsible for the injury.
Dramatic impact is when the shooter seeks notoriety/attention and choose his victims for their vulnerability, creating angry and devastated relatives and friends in a wide range.
Maximum chaos is just that - the desire to cause as much human harm as possible, to terrorize and intimidate as large a group of people as possible. The victims are then not only the ones that were shot, but all those who see the incident and react adversely to it. Usually causes changes in law, security, procedures, appearances and societal disruption. For a prime example, the shoe bomber was one person who tried to detonate a bomb on an aircraft, using his shoe as the delivery method for the explosive. Since that time, aircraft passengers are required to remove their shoes. One single terrorist was able to affect literally millions of people.
This is not hard to figure out. The people who want to do mass killing is going to not care who is caught in the bomb, vehicle, gun, or other kind of attack. This is why it is called terror. They are trying to cause terror and have people be fearful of going outside. There fore if that happens they win.